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