blob: fed9275c6d36fd5390b65011705d9c3a8d1fd832 [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
287 <para>Also, <literal>-fomit-frame-pointer</literal> and
288 <literal>-fstack-check</literal> can make stack traces
289 worse.</para>
290
291 <para>Some example sub-traces:</para>
292
293 <para>With debug information and unstripped (best):</para>
294<programlisting>
295Invalid write of size 1
296 at 0x80483BF: really (malloc1.c:20)
297 by 0x8048370: main (malloc1.c:9)
298</programlisting>
299
300 <para>With no debug information, unstripped:</para>
301<programlisting>
302Invalid write of size 1
303 at 0x80483BF: really (in /auto/homes/njn25/grind/head5/a.out)
304 by 0x8048370: main (in /auto/homes/njn25/grind/head5/a.out)
305</programlisting>
306
307 <para>With no debug information, stripped:</para>
308<programlisting>
309Invalid write of size 1
310 at 0x80483BF: (within /auto/homes/njn25/grind/head5/a.out)
311 by 0x8048370: (within /auto/homes/njn25/grind/head5/a.out)
312 by 0x42015703: __libc_start_main (in /lib/tls/libc-2.3.2.so)
313 by 0x80482CC: (within /auto/homes/njn25/grind/head5/a.out)
314</programlisting>
315
316 <para>With debug information and -fomit-frame-pointer:</para>
317<programlisting>
318Invalid write of size 1
319 at 0x80483C4: really (malloc1.c:20)
320 by 0x42015703: __libc_start_main (in /lib/tls/libc-2.3.2.so)
321 by 0x80482CC: ??? (start.S:81)
322</programlisting>
323
324 </answer>
325</qandaentry>
326
327</qandaset>
328</chapter>
329
330
331<chapter id="faq.notfound" xreflabel="Memcheck doesn't find my bug">
332<title>Memcheck doesn't find my bug</title>
333<qandaset id="qset.notfound">
334
335<qandaentry id="faq.hiddenbug">
336 <question>
337 <para>I try running "valgrind --tool=memcheck my_program" and
338 get Valgrind's startup message, but I don't get any errors and
339 I know my program has errors.</para>
340 </question>
341 <answer>
njna11b9b02005-03-27 17:05:08 +0000342 <para>There are two possible causes of this.</para>
343
344 <para>First, by default, Valgrind only traces the top-level process.
njn3e986b22004-11-30 10:43:45 +0000345 So if your program spawns children, they won't be traced by
346 Valgrind by default. Also, if your program is started by a
347 shell script, Perl script, or something similar, Valgrind will
348 trace the shell, or the Perl interpreter, or equivalent.</para>
349
350 <para>To trace child processes, use the
351 <literal>--trace-children=yes</literal> option.</para>
352
353 <para>If you are tracing large trees of processes, it can be
354 less disruptive to have the output sent over the network. Give
355 Valgrind the flag
356 <literal>--log-socket=127.0.0.1:12345</literal> (if you want
357 logging output sent to <literal>port 12345</literal> on
358 <literal>localhost</literal>). You can use the
359 valgrind-listener program to listen on that port:</para>
360<programlisting>
361valgrind-listener 12345
362</programlisting>
363
364 <para>Obviously you have to start the listener process first.
365 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 +0000366
367 <para>Second, if your program is statically linked, most Valgrind tools
368 won't work as well, because they won't be able to replace certain
369 functions, such as malloc(), with their own versions. A key indicator of
370 this is if Memcheck says:
371<programlisting>
372No malloc'd blocks -- no leaks are possible
373</programlisting>
374when you know your program calls malloc(). The workaround is to avoid
375statically linking your program.</para>
njn3e986b22004-11-30 10:43:45 +0000376 </answer>
377</qandaentry>
378
379
380<qandaentry id="faq.overruns">
381 <question>
382 <para>Why doesn't Memcheck find the array overruns in this program?</para>
383 </question>
384 <answer>
385<programlisting>
386int static[5];
387
388int main(void)
389{
390 int stack[5];
391
392 static[5] = 0;
393 stack [5] = 0;
394
395 return 0;
396}
397</programlisting>
398 <para>Unfortunately, Memcheck doesn't do bounds checking on
399 static or stack arrays. We'd like to, but it's just not
400 possible to do in a reasonable way that fits with how Memcheck
401 works. Sorry.</para>
402 </answer>
403</qandaentry>
404
405
njn3e986b22004-11-30 10:43:45 +0000406</qandaset>
407</chapter>
408
409
410<chapter id="faq.misc"
411 xreflabel="Miscellaneous">
412<title>Miscellaneous</title>
413<qandaset id="qset.misc">
414
415<qandaentry id="faq.writesupp">
416 <question>
417 <para>I tried writing a suppression but it didn't work. Can
418 you write my suppression for me?</para>
419 </question>
420 <answer>
421 <para>Yes! Use the
422 <computeroutput>--gen-suppressions=yes</computeroutput> feature
423 to spit out suppressions automatically for you. You can then
424 edit them if you like, eg. combining similar automatically
425 generated suppressions using wildcards like
426 <literal>'*'</literal>.</para>
427
428 <para>If you really want to write suppressions by hand, read
429 the manual carefully. Note particularly that C++ function
430 names must be <literal>_mangled_</literal>.</para>
431 </answer>
432</qandaentry>
433
434
435<qandaentry id="faq.deflost">
436 <question>
437 <para>With Memcheck/Addrcheck's memory leak detector, what's
438 the difference between "definitely lost", "possibly lost",
439 "still reachable", and "suppressed"?</para>
440 </question>
441 <answer>
442 <para>The details are in the Manual:
443 <ulink url="http://www.valgrind.org/docs/bookset/mc-manual.leaks.html">Memory leak detection</ulink>.</para>
444
445 <para>In short:</para>
446 <itemizedlist>
447 <listitem>
448 <para>"definitely lost" means your program is leaking memory
449 -- fix it!</para>
450 </listitem>
451 <listitem>
452 <para>"possibly lost" means your program is probably leaking
453 memory, unless you're doing funny things with
454 pointers.</para>
455 </listitem>
456 <listitem>
457 <para>"still reachable" means your program is probably ok --
458 it didn't free some memory it could have. This is quite
459 common and often reasonable. Don't use
460 <computeroutput>--show-reachable=yes</computeroutput> if you
461 don't want to see these reports.</para>
462 </listitem>
463 <listitem>
464 <para>"suppressed" means that a leak error has been
465 suppressed. There are some suppressions in the default
466 suppression files. You can ignore suppressed errors.</para>
467 </listitem>
468 </itemizedlist>
469 </answer>
470</qandaentry>
471
472
473</qandaset>
474</chapter>
475
476
477<!-- template
478<chapter id="faq."
479 xreflabel="xx">
480<title>xx</title>
481<qandaset id="qset.">
482
483<qandaentry id="faq.deflost">
484 <question>
485 <para></para>
486 </question>
487 <answer>
488 <para></para>
489 </answer>
490</qandaentry>
491
492</qandaset>
493</chapter>
494-->
495
496
497
498<chapter id="faq.help" xreflabel="How To Get Further Assistance">
499<title>How To Get Further Assistance</title>
500
501
502<para>Please read all of this section before posting.</para>
503
504<para>If you think an answer is incomplete or inaccurate, please
505e-mail <ulink url="mailto:&vg-vemail;">&vg-vemail;</ulink>.</para>
506
507<para>Read the appropriate section(s) of the Manual(s):
508<ulink url="http://www.valgrind.org/docs/">Valgrind
509Documentation</ulink>.</para>
510
511<para>Read the <ulink url="http://www.valgrind.org/docs/">Distribution Documents</ulink>.</para>
512
513<para><ulink url="http://search.gmane.org">Search</ulink> the
514<ulink url="http://news.gmane.org/gmane.comp.debugging.valgrind">valgrind-users</ulink> mailing list archives, using the group name
515<computeroutput>gmane.comp.debugging.valgrind</computeroutput>.</para>
516
517<para>Only when you have tried all of these things and are still stuck,
518should you post to the <ulink url="&vg-users-list;">valgrind-users
519mailing list</ulink>. In which case, please read the following
520carefully. Making a complete posting will greatly increase the chances
521that an expert or fellow user reading it will have enough information
522and motivation to reply.</para>
523
524<para>Make sure you give full details of the problem,
525including the full output of <computeroutput>valgrind
526-v</computeroutput>, if applicable. Also which Linux distribution
527you're using (Red Hat, Debian, etc) and its version number.</para>
528
529<para>You are in little danger of making your posting too long
530unless you include large chunks of valgrind's (unsuppressed)
531output, so err on the side of giving too much information.</para>
532
533<para>Clearly written subject lines and message bodies are appreciated,
534too.</para>
535
536<para>Finally, remember that, despite the fact that most of the
537community are very helpful and responsive to emailed questions,
538you are probably requesting help from unpaid volunteers, so you
539have no guarantee of receiving an answer.</para>
540
541</chapter>
542
543</book>