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