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