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