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 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 97 | </qandadiv> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 98 | |
| 99 | |
| 100 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 101 | <!-- Valgrind aborts unexpectedly --> |
| 102 | <qandadiv id="faq.abort" xreflabel="Valgrind aborts unexpectedly"> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 103 | <title>Valgrind aborts unexpectedly</title> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 104 | |
| 105 | <qandaentry id="faq.exit_errors"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 106 | <question id="q-exit_errors"> |
| 107 | <para>Programs run OK on Valgrind, but at exit produce a bunch of |
| 108 | errors involving <literal>__libc_freeres()</literal> and then die |
| 109 | with a segmentation fault.</para> |
| 110 | </question> |
| 111 | <answer id="a-exit_errors"> |
| 112 | <para>When the program exits, Valgrind runs the procedure |
| 113 | <function>__libc_freeres()</function> in glibc. This is a hook for |
| 114 | memory debuggers, so they can ask glibc to free up any memory it has |
| 115 | used. Doing that is needed to ensure that Valgrind doesn't |
| 116 | incorrectly report space leaks in glibc.</para> |
| 117 | |
| 118 | <para>Problem is that running <literal>__libc_freeres()</literal> in |
| 119 | older glibc versions causes this crash.</para> |
| 120 | |
| 121 | <para>WORKAROUND FOR 1.1.X and later versions of Valgrind: use the |
| 122 | <option>--run-libc-freeres=no</option> flag. You may then get space |
| 123 | leak reports for glibc-allocations (please _don't_ report these to |
| 124 | the glibc people, since they are not real leaks), but at least the |
| 125 | program runs.</para> |
| 126 | </answer> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 127 | </qandaentry> |
| 128 | |
| 129 | <qandaentry id="faq.bugdeath"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 130 | <question id="q-bugdeath"> |
| 131 | <para>My (buggy) program dies like this:</para> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 132 | <screen>% valgrind: vg_malloc2.c:442 (bszW_to_pszW): Assertion 'pszW >= 0' failed.</screen> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 133 | </question> |
| 134 | <answer id="a-bugdeath"> |
| 135 | <para>If Memcheck (the memory checker) shows any invalid reads, |
| 136 | invalid writes and invalid frees in your program, the above may |
| 137 | happen. Reason is that your program may trash Valgrind's low-level |
| 138 | memory manager, which then dies with the above assertion, or |
| 139 | something like this. The cure is to fix your program so that it |
| 140 | doesn't do any illegal memory accesses. The above failure will |
| 141 | hopefully go away after that.</para> |
| 142 | </answer> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 143 | </qandaentry> |
| 144 | |
| 145 | <qandaentry id="faq.msgdeath"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 146 | <question id="q-msgdeath"> |
| 147 | <para>My program dies, printing a message like this along the |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 148 | way:</para> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 149 | <screen>% disInstr: unhandled instruction bytes: 0x66 0xF 0x2E 0x5</screen> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 150 | </question> |
| 151 | <answer id="a-msgdeath"> |
| 152 | <para>Older versions did not support some x86 instructions, |
| 153 | particularly SSE/SSE2 instructions. Try a newer Valgrind; we now |
| 154 | support almost all instructions. If it still happens with newer |
| 155 | versions, if the failing instruction is an SSE/SSE2 instruction, you |
| 156 | might be able to recompile your program without it by using the flag |
| 157 | <option>-march</option> to gcc. Either way, let us know and we'll |
| 158 | try to fix it.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 159 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 160 | <para>Another possibility is that your program has a bug and |
| 161 | erroneously jumps to a non-code address, in which case you'll get a |
| 162 | SIGILL signal. Memcheck/Addrcheck may issue a warning just before |
| 163 | this happens, but they might not if the jump happens to land in |
| 164 | addressable memory.</para> |
| 165 | </answer> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 166 | </qandaentry> |
| 167 | |
njn | dde37b4 | 2005-10-06 18:58:33 +0000 | [diff] [blame] | 168 | <qandaentry id="faq.java"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 169 | <question id="q-java"> |
| 170 | <para>I tried running a Java program (or another program that uses a |
| 171 | just-in-time compiler) under Valgrind but something went wrong. |
| 172 | Does Valgrind handle such programs?</para> |
| 173 | </question> |
| 174 | <answer id="a-java"> |
| 175 | <para>Valgrind can handle dynamically generated code, so long as |
| 176 | none of the generated code is later overwritten by other generated |
| 177 | code. If this happens, though, things will go wrong as Valgrind |
| 178 | will continue running its translations of the old code (this is true |
| 179 | on x86 and AMD64, on PPC32 there are explicit cache flush |
| 180 | instructions which Valgrind detects). You should try running with |
| 181 | <option>--smc-check=all</option> in this case; Valgrind will run |
| 182 | much more slowly, but should detect the use of the out-of-date |
| 183 | code.</para> |
| 184 | |
| 185 | <para>Alternativaly, if you have the source code to the JIT compiler |
| 186 | you can insert calls to the |
| 187 | <computeroutput>VALGRIND_DISCARD_TRANSLATIONS</computeroutput> |
| 188 | client request to mark out-of-date code, saving you from using |
| 189 | <option>--smc-check=all</option>.</para> |
| 190 | |
| 191 | <para>Apart from this, in theory Valgrind can run any Java program |
| 192 | just fine, even those that use JNI and are partially implemented in |
| 193 | other languages like C and C++. In practice, Java implementations |
| 194 | tend to do nasty things that most programs do not, and Valgrind |
| 195 | sometimes falls over these corner cases.</para> |
| 196 | |
| 197 | <para>If your Java programs do not run under Valgrind, even with |
| 198 | <option>--smc-check=all</option>, please file a bug report and |
| 199 | hopefully we'll be able to fix the problem.</para> |
| 200 | </answer> |
njn | dde37b4 | 2005-10-06 18:58:33 +0000 | [diff] [blame] | 201 | </qandaentry> |
| 202 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 203 | </qandadiv> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 204 | |
| 205 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 206 | <!-- Valgrind behaves unexpectedly --> |
| 207 | <qandadiv id="faq.unexpected" xreflabel="Valgrind behaves unexpectedly"> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 208 | <title>Valgrind behaves unexpectedly</title> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 209 | |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 210 | <qandaentry id="faq.reports"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 211 | <question id="q-reports"> |
| 212 | <para>My program uses the C++ STL and string classes. Valgrind |
| 213 | reports 'still reachable' memory leaks involving these classes at |
| 214 | the exit of the program, but there should be none.</para> |
| 215 | </question> |
| 216 | <answer id="a-reports"> |
| 217 | <para>First of all: relax, it's probably not a bug, but a feature. |
| 218 | Many implementations of the C++ standard libraries use their own |
| 219 | memory pool allocators. Memory for quite a number of destructed |
| 220 | objects is not immediately freed and given back to the OS, but kept |
| 221 | in the pool(s) for later re-use. The fact that the pools are not |
| 222 | freed at the exit() of the program cause Valgrind to report this |
| 223 | memory as still reachable. The behaviour not to free pools at the |
| 224 | exit() could be called a bug of the library though.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 225 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 226 | <para>Using gcc, you can force the STL to use malloc and to free |
| 227 | memory as soon as possible by globally disabling memory caching. |
| 228 | Beware! Doing so will probably slow down your program, sometimes |
| 229 | drastically.</para> |
| 230 | <itemizedlist> |
| 231 | <listitem> |
| 232 | <para>With gcc 2.91, 2.95, 3.0 and 3.1, compile all source using |
| 233 | the STL with <literal>-D__USE_MALLOC</literal>. Beware! This is |
| 234 | removed from gcc starting with version 3.3.</para> |
| 235 | </listitem> |
| 236 | <listitem> |
| 237 | <para>With gcc 3.2.2 and later, you should export the |
| 238 | environment variable <literal>GLIBCPP_FORCE_NEW</literal> before |
| 239 | running your program.</para> |
| 240 | </listitem> |
| 241 | <listitem> |
| 242 | <para>With gcc 3.4 and later, that variable has changed name to |
| 243 | <literal>GLIBCXX_FORCE_NEW</literal>.</para> |
| 244 | </listitem> |
| 245 | </itemizedlist> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 246 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 247 | <para>There are other ways to disable memory pooling: using the |
| 248 | <literal>malloc_alloc</literal> template with your objects (not |
| 249 | portable, but should work for gcc) or even writing your own memory |
| 250 | allocators. But all this goes beyond the scope of this FAQ. Start |
| 251 | by reading |
| 252 | <ulink url="http://gcc.gnu.org/onlinedocs/libstdc++/ext/howto.html#3"> |
| 253 | http://gcc.gnu.org/onlinedocs/libstdc++/ext/howto.html#3</ulink> if |
| 254 | you absolutely want to do that. But beware:</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 255 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 256 | <orderedlist> |
| 257 | <listitem> |
| 258 | <para>there are currently changes underway for gcc which are not |
| 259 | totally reflected in the docs right now ("now" == 26 Apr 03)</para> |
| 260 | </listitem> |
| 261 | <listitem> |
| 262 | <para>allocators belong to the more messy parts of the STL and |
| 263 | people went to great lengths to make it portable across |
| 264 | platforms. Chances are good that your solution will work on your |
| 265 | platform, but not on others.</para> |
| 266 | </listitem> |
| 267 | </orderedlist> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 268 | </answer> |
| 269 | </qandaentry> |
| 270 | |
| 271 | |
| 272 | <qandaentry id="faq.unhelpful"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 273 | <question id="q-unhelpful"> |
| 274 | <para>The stack traces given by Memcheck (or another tool) aren't |
| 275 | helpful. How can I improve them?</para> |
| 276 | </question> |
| 277 | <answer id="a-unhelpful"> |
| 278 | <para>If they're not long enough, use <option>--num-callers</option> |
| 279 | to make them longer.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 280 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 281 | <para>If they're not detailed enough, make sure you are compiling |
| 282 | with <option>-g</option> to add debug information. And don't strip |
| 283 | symbol tables (programs should be unstripped unless you run 'strip' |
| 284 | on them; some libraries ship stripped).</para> |
njn | 0211ff3 | 2005-05-15 14:49:24 +0000 | [diff] [blame] | 285 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 286 | <para>Also, for leak reports involving shared objects, if the shared |
| 287 | object is unloaded before the program terminates, Valgrind will |
| 288 | discard the debug information and the error message will be full of |
| 289 | <literal>???</literal> entries. The workaround here is to avoid |
| 290 | calling dlclose() on these shared objects.</para> |
| 291 | |
| 292 | <para>Also, <option>-fomit-frame-pointer</option> and |
| 293 | <option>-fstack-check</option> can make stack traces worse.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 294 | |
| 295 | <para>Some example sub-traces:</para> |
| 296 | |
njn | 15d7c34 | 2005-09-30 01:43:32 +0000 | [diff] [blame] | 297 | <itemizedlist> |
| 298 | <listitem> |
| 299 | <para>With debug information and unstripped (best):</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 300 | <programlisting> |
| 301 | Invalid write of size 1 |
| 302 | at 0x80483BF: really (malloc1.c:20) |
| 303 | by 0x8048370: main (malloc1.c:9) |
| 304 | </programlisting> |
njn | 15d7c34 | 2005-09-30 01:43:32 +0000 | [diff] [blame] | 305 | </listitem> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 306 | |
njn | 15d7c34 | 2005-09-30 01:43:32 +0000 | [diff] [blame] | 307 | <listitem> |
| 308 | <para>With no debug information, unstripped:</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 309 | <programlisting> |
| 310 | Invalid write of size 1 |
| 311 | at 0x80483BF: really (in /auto/homes/njn25/grind/head5/a.out) |
| 312 | by 0x8048370: main (in /auto/homes/njn25/grind/head5/a.out) |
| 313 | </programlisting> |
njn | 15d7c34 | 2005-09-30 01:43:32 +0000 | [diff] [blame] | 314 | </listitem> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 315 | |
njn | 15d7c34 | 2005-09-30 01:43:32 +0000 | [diff] [blame] | 316 | <listitem> |
| 317 | <para>With no debug information, stripped:</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 318 | <programlisting> |
| 319 | Invalid write of size 1 |
| 320 | at 0x80483BF: (within /auto/homes/njn25/grind/head5/a.out) |
| 321 | by 0x8048370: (within /auto/homes/njn25/grind/head5/a.out) |
| 322 | by 0x42015703: __libc_start_main (in /lib/tls/libc-2.3.2.so) |
| 323 | by 0x80482CC: (within /auto/homes/njn25/grind/head5/a.out) |
| 324 | </programlisting> |
njn | 15d7c34 | 2005-09-30 01:43:32 +0000 | [diff] [blame] | 325 | </listitem> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 326 | |
njn | 15d7c34 | 2005-09-30 01:43:32 +0000 | [diff] [blame] | 327 | <listitem> |
| 328 | <para>With debug information and -fomit-frame-pointer:</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 329 | <programlisting> |
| 330 | Invalid write of size 1 |
| 331 | at 0x80483C4: really (malloc1.c:20) |
| 332 | by 0x42015703: __libc_start_main (in /lib/tls/libc-2.3.2.so) |
| 333 | by 0x80482CC: ??? (start.S:81) |
| 334 | </programlisting> |
njn | 15d7c34 | 2005-09-30 01:43:32 +0000 | [diff] [blame] | 335 | </listitem> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 336 | |
njn | 15d7c34 | 2005-09-30 01:43:32 +0000 | [diff] [blame] | 337 | <listitem> |
| 338 | <para>A leak error message involving an unloaded shared object:</para> |
njn | 0211ff3 | 2005-05-15 14:49:24 +0000 | [diff] [blame] | 339 | <programlisting> |
| 340 | 84 bytes in 1 blocks are possibly lost in loss record 488 of 713 |
| 341 | at 0x1B9036DA: operator new(unsigned) (vg_replace_malloc.c:132) |
| 342 | by 0x1DB63EEB: ??? |
| 343 | by 0x1DB4B800: ??? |
| 344 | by 0x1D65E007: ??? |
| 345 | by 0x8049EE6: main (main.cpp:24) |
| 346 | </programlisting> |
njn | 15d7c34 | 2005-09-30 01:43:32 +0000 | [diff] [blame] | 347 | </listitem> |
| 348 | </itemizedlist> |
njn | 0211ff3 | 2005-05-15 14:49:24 +0000 | [diff] [blame] | 349 | |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 350 | </answer> |
| 351 | </qandaentry> |
| 352 | |
njn | 16eeb4e | 2005-06-16 03:56:58 +0000 | [diff] [blame] | 353 | <qandaentry id="faq.aliases"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 354 | <question id="q-aliases"> |
| 355 | <para>The stack traces given by Memcheck (or another tool) seem to |
| 356 | have the wrong function name in them. What's happening?</para> |
| 357 | </question> |
| 358 | <answer id="a-aliases"> |
| 359 | <para>Occasionally Valgrind stack traces get the wrong function |
| 360 | names. This is caused by glibc using aliases to effectively give |
| 361 | one function two names. Most of the time Valgrind chooses a |
| 362 | suitable name, but very occasionally it gets it wrong. Examples we |
| 363 | know of are printing 'bcmp' instead of 'memcmp', 'index' instead of |
| 364 | 'strchr', and 'rindex' instead of 'strrchr'.</para> |
| 365 | </answer> |
njn | 16eeb4e | 2005-06-16 03:56:58 +0000 | [diff] [blame] | 366 | </qandaentry> |
| 367 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 368 | </qandadiv> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 369 | |
| 370 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 371 | |
| 372 | <!-- Memcheck doesn't find my bug --> |
| 373 | <qandadiv id="faq.notfound" xreflabel="Memcheck doesn't find my bug"> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 374 | <title>Memcheck doesn't find my bug</title> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 375 | |
| 376 | <qandaentry id="faq.hiddenbug"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 377 | <question id="q-hiddenbug"> |
| 378 | <para>I try running "valgrind --tool=memcheck my_program" and get |
| 379 | Valgrind's startup message, but I don't get any errors and I know my |
| 380 | program has errors.</para> |
| 381 | </question> |
| 382 | <answer id="a-hiddenbug"> |
| 383 | <para>There are two possible causes of this.</para> |
njn | a11b9b0 | 2005-03-27 17:05:08 +0000 | [diff] [blame] | 384 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 385 | <para>First, by default, Valgrind only traces the top-level process. |
| 386 | So if your program spawns children, they won't be traced by Valgrind |
| 387 | by default. Also, if your program is started by a shell script, |
| 388 | Perl script, or something similar, Valgrind will trace the shell, or |
| 389 | the Perl interpreter, or equivalent.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 390 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 391 | <para>To trace child processes, use the |
| 392 | <option>--trace-children=yes</option> option.</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>If you are tracing large trees of processes, it can be less |
| 395 | disruptive to have the output sent over the network. Give Valgrind |
| 396 | the flag <option>--log-socket=127.0.0.1:12345</option> (if you want |
| 397 | logging output sent to <literal>port 12345</literal> on |
| 398 | <literal>localhost</literal>). You can use the valgrind-listener |
| 399 | program to listen on that port:</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 400 | <programlisting> |
| 401 | valgrind-listener 12345 |
| 402 | </programlisting> |
| 403 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 404 | <para>Obviously you have to start the listener process first. See |
| 405 | the manual for more details.</para> |
njn | a11b9b0 | 2005-03-27 17:05:08 +0000 | [diff] [blame] | 406 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 407 | <para>Second, if your program is statically linked, most Valgrind |
| 408 | tools won't work as well, because they won't be able to replace |
| 409 | certain functions, such as malloc(), with their own versions. A key |
| 410 | indicator of this is if Memcheck says: |
njn | a11b9b0 | 2005-03-27 17:05:08 +0000 | [diff] [blame] | 411 | <programlisting> |
njn | 5666ee6 | 2005-12-19 19:38:02 +0000 | [diff] [blame^] | 412 | All heap blocks were freed -- no leaks are possible |
njn | a11b9b0 | 2005-03-27 17:05:08 +0000 | [diff] [blame] | 413 | </programlisting> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 414 | when you know your program calls malloc(). The workaround is to |
| 415 | avoid statically linking your program.</para> |
| 416 | </answer> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 417 | </qandaentry> |
| 418 | |
| 419 | |
| 420 | <qandaentry id="faq.overruns"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 421 | <question id="q-overruns"> |
| 422 | <para>Why doesn't Memcheck find the array overruns in this |
| 423 | program?</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 424 | <programlisting> |
| 425 | int static[5]; |
| 426 | |
| 427 | int main(void) |
| 428 | { |
| 429 | int stack[5]; |
| 430 | |
| 431 | static[5] = 0; |
| 432 | stack [5] = 0; |
| 433 | |
| 434 | return 0; |
| 435 | } |
| 436 | </programlisting> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 437 | </question> |
| 438 | <answer id="a-overruns"> |
| 439 | <para>Unfortunately, Memcheck doesn't do bounds checking on static |
| 440 | or stack arrays. We'd like to, but it's just not possible to do in |
| 441 | a reasonable way that fits with how Memcheck works. Sorry.</para> |
| 442 | </answer> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 443 | </qandaentry> |
| 444 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 445 | </qandadiv> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 446 | |
| 447 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 448 | |
| 449 | <!-- Miscellaneous --> |
| 450 | <qandadiv id="faq.misc" xreflabel="Miscellaneous"> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 451 | <title>Miscellaneous</title> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 452 | |
| 453 | <qandaentry id="faq.writesupp"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 454 | <question id="q-writesupp"> |
| 455 | <para>I tried writing a suppression but it didn't work. Can you |
| 456 | write my suppression for me?</para> |
| 457 | </question> |
| 458 | <answer id="a-writesupp"> |
| 459 | <para>Yes! Use the <option>--gen-suppressions=yes</option> feature |
| 460 | to spit out suppressions automatically for you. You can then edit |
| 461 | them if you like, eg. combining similar automatically generated |
| 462 | suppressions using wildcards like <literal>'*'</literal>.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 463 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 464 | <para>If you really want to write suppressions by hand, read the |
| 465 | manual carefully. Note particularly that C++ function names must be |
| 466 | <literal>_mangled_</literal>.</para> |
| 467 | </answer> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 468 | </qandaentry> |
| 469 | |
| 470 | |
| 471 | <qandaentry id="faq.deflost"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 472 | <question id="q-deflost"> |
| 473 | <para>With Memcheck/Addrcheck's memory leak detector, what's the |
| 474 | difference between "definitely lost", "possibly lost", "still |
| 475 | reachable", and "suppressed"?</para> |
| 476 | </question> |
| 477 | <answer id="a-deflost"> |
| 478 | <para>The details are in the Memcheck section of the user |
| 479 | manual.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 480 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 481 | <para>In short:</para> |
| 482 | <itemizedlist> |
| 483 | <listitem> |
| 484 | <para>"definitely lost" means your program is leaking memory -- |
| 485 | fix it!</para> |
| 486 | </listitem> |
| 487 | <listitem> |
| 488 | <para>"possibly lost" means your program is probably leaking |
| 489 | memory, unless you're doing funny things with pointers.</para> |
| 490 | </listitem> |
| 491 | <listitem> |
| 492 | <para>"still reachable" means your program is probably ok -- it |
| 493 | didn't free some memory it could have. This is quite common and |
| 494 | often reasonable. Don't use |
| 495 | <option>--show-reachable=yes</option> if you don't want to see |
| 496 | these reports.</para> |
| 497 | </listitem> |
| 498 | <listitem> |
| 499 | <para>"suppressed" means that a leak error has been suppressed. |
| 500 | There are some suppressions in the default suppression files. |
| 501 | You can ignore suppressed errors.</para> |
| 502 | </listitem> |
| 503 | </itemizedlist> |
| 504 | </answer> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 505 | </qandaentry> |
| 506 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 507 | </qandadiv> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 508 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 509 | |
| 510 | |
| 511 | <!-- Further Assistance --> |
| 512 | <qandadiv id="faq.help" xreflabel="How To Get Further Assistance"> |
| 513 | <title>How To Get Further Assistance</title> |
| 514 | |
| 515 | <qandaentry id="e-help"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 516 | <!-- <question><para/></question> --> |
| 517 | <answer id="a-help"> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 518 | <para>Please read all of this section before posting.</para> |
| 519 | |
| 520 | <para>If you think an answer is incomplete or inaccurate, please |
| 521 | e-mail <ulink url="mailto:&vg-vemail;">&vg-vemail;</ulink>.</para> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 522 | |
de | 97ab7e7 | 2005-11-27 18:19:40 +0000 | [diff] [blame] | 523 | <para>Read the appropriate section(s) of the |
| 524 | <ulink url="&vg-bookset;">Valgrind Documentation</ulink>.</para> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 525 | |
de | 97ab7e7 | 2005-11-27 18:19:40 +0000 | [diff] [blame] | 526 | <para>Read the |
| 527 | <ulink url="&vg-dist-docs;">Distribution Documents</ulink>.</para> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 528 | |
| 529 | <para><ulink url="http://search.gmane.org">Search</ulink> the |
| 530 | <ulink url="http://news.gmane.org/gmane.comp.debugging.valgrind">valgrind-users</ulink> mailing list archives, using the group name |
| 531 | <computeroutput>gmane.comp.debugging.valgrind</computeroutput>.</para> |
| 532 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 533 | <para>Only when you have tried all of these things and are still |
| 534 | stuck, should you post to the |
| 535 | <ulink url="&vg-users-list;">valgrind-users mailing list</ulink>. In |
| 536 | which case, please read the following carefully. Making a complete |
| 537 | posting will greatly increase the chances that an expert or fellow |
| 538 | user reading it will have enough information and motivation to |
| 539 | reply.</para> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 540 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 541 | <para>Make sure you give full details of the problem, including the |
njn | 1ac2f0d | 2005-12-04 19:26:00 +0000 | [diff] [blame] | 542 | full output of <computeroutput>valgrind -v <your-prog></computeroutput>, if |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 543 | applicable. Also which Linux distribution you're using (Red Hat, |
| 544 | Debian, etc) and its version number.</para> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 545 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 546 | <para>You are in little danger of making your posting too long unless |
| 547 | you include large chunks of Valgrind's (unsuppressed) output, so err |
| 548 | on the side of giving too much information.</para> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 549 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 550 | <para>Clearly written subject lines and message bodies are |
| 551 | appreciated, too.</para> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 552 | |
| 553 | <para>Finally, remember that, despite the fact that most of the |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 554 | community are very helpful and responsive to emailed questions, you |
| 555 | are probably requesting help from unpaid volunteers, so you have no |
| 556 | guarantee of receiving an answer.</para> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 557 | </answer> |
| 558 | |
| 559 | </qandaentry> |
| 560 | </qandadiv> |
| 561 | |
| 562 | |
| 563 | <!-- FAQ ends here --> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 564 | </qandaset> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 565 | |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 566 | |
| 567 | |
| 568 | <!-- template |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 569 | <qandadiv id="faq.installing" xreflabel="Installing"> |
| 570 | <title>Installing</title> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 571 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 572 | <qandaentry id="faq.problem"> |
| 573 | <question id="q-problem"> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 574 | <para></para> |
| 575 | </question> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 576 | <answer id="a-problem"> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 577 | <para></para> |
| 578 | </answer> |
| 579 | </qandaentry> |
| 580 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 581 | </qandadiv> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 582 | --> |
| 583 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 584 | </article> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 585 | |
| 586 | </book> |