blob: d058fd036ac72f17c0df349f0ceb4070fdd4dae8 [file] [log] [blame]
njn74e70122005-03-12 21:02:52 +00001.TH VALGRIND "1" "" ""
2
3.SH NAME
njn51272982005-07-25 23:18:44 +00004\fBvalgrind \fP- a suite of tools for debugging and profiling programs
njn74e70122005-03-12 21:02:52 +00005
6.SH SYNOPSIS
7.nf
8.fam C
9\fIvalgrind\fP [\fIvalgrind\fP \fIoptions\fP] \fIyour-program\fP [\fIyour-program\fP \fIoptions\fP]
10.fam T
11.fi
12
13.SH DESCRIPTION
njn51272982005-07-25 23:18:44 +000014\fBvalgrind\fP is a flexible program for debugging and profiling Linux
15executables. It consists of a core, which provides a synthetic CPU
njn74e70122005-03-12 21:02:52 +000016in software, and a series of "tools", each of which is a debugging or
17profiling tool. The architecture is modular, so that new tools can be
18created easily and without disturbing the existing structure.
19
20.PP
21This manual page covers only basic usage and options. Please see the
22HTML documentation for more comprehensive information.
23
24.SH INVOCATION
25\fBvalgrind\fP is typically invoked as follows:
26
27 valgrind program args
28
29This runs \fBprogram\fP (with arguments \fBargs\fP) under valgrind
30using the \fBmemcheck\fP tool. \fBmemcheck\fP performs a range of
31memory-checking functions, including detecting accesses to uninitialized
32memory, misuse of allocated memory (double frees, access after free,
33etc.) and detecting memory leaks.
34
35To use a different tool, use the \fB--tool\fP option:
36
37 valgrind --tool=toolname program args
38
39The following tools are available:
40
41.RS
42.TP
43.B
44- addrcheck
45\fBaddrcheck\fP is similar to memcheck, but does not perform the same
46granularity of memory checking. This will run faster and use less memory,
47but may miss some problems that \fBmemcheck\fP would catch.
48.TP
49.B
50- cachegrind
51\fBcachegrind\fP is a cache simulator.
52." .TP
53." .B
54." - helgrind
55." \fBhelgrind\fP spots potential race conditions in your program.
56.TP
57.B
58- lackey
59\fBlackey\fP is a sample tool that can be used as a template for
60generating your own tools. After the program terminates, it prints out
61some basic statistics about the program execution.
62.TP
63.B
64- massif
65\fBmassif\fP is a heap profiler. It measures how much heap memory your
66program uses.
67.TP
68.B
69- memcheck
70\fBmemcheck\fP is a fine-grained memory checker.
71.TP
72.B
73- none
74\fBnone\fP performs no function - it simply runs the program under
75\fBvalgrind\fP. This is typically used for debugging and benchmarking
76\fBvalgrind\fP.
77.RE
78
79.SH COMMON CORE OPTIONS
80
81.TP
82.B
83--db-attach=<yes|no> [default: no]
84When enabled, \fBvalgrind\fP will pause after every error shown and
85print the line:
86
87.PP
88.nf
89.fam C
90 ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ----
91
92.fam T
93.fi
94
95.RS
96Pressing Ret, or N Ret or n Ret, causes \fBvalgrind\fP not to start a
97debugger for this error.
98
99.PP
100Pressing Y Ret or y Ret causes \fBvalgrind\fP to start the debugger
101(specified by the \fB--db-command\fP option) for the program at this
102point. When you have finished with the debugger, quit from it, and
103the program will continue. Trying to continue from inside the debugger
104doesn't work.
105
106.PP
107Pressing C Ret or c Ret causes \fBvalgrind\fP not to start the debugger
108and \fBvalgrind\fP will not ask again.
109
110.PP
111--db-attach=yes conflicts with --trace-children=yes. You can't use them
112together. \fBvalgrind\fP refuses to start up in this situation. 1 May
1132002: this is a historical relic which could be easily fixed if it gets
114in your way. Mail me and complain if this is a problem for you.
115
116.PP
117Nov 2002: if you're sending output to a logfile or to a network socket,
118I guess this option doesn't make any sense. Caveat emptor.
119.RE
120
121.TP
122.B
123--db-command=<command> [default: gdb -nw %f %p]
124Specify the debugger to use with the --db-attach command. The
125default debugger is gdb. This option is a template that is expanded by
126\fBvalgrind\fP at runtime. \fB%f\fP is replaced with the executable's
127file name and \fB%p\fP is replaced by the process ID of the executable.
njn51272982005-07-25 23:18:44 +0000128
njn74e70122005-03-12 21:02:52 +0000129.TP
130.B
njn51272982005-07-25 23:18:44 +0000131--demangle=<yes|no> [default: yes]
132Enable or disable automatic demangling (decoding) of C++ names. Enabled by
133default. When enabled, \fBvalgrind\fP will attempt to translate encoded
134C++ procedure names back to something approaching the original. The
135demangler handles symbols mangled by g++ versions 2.X and 3.X.
njn74e70122005-03-12 21:02:52 +0000136
njn51272982005-07-25 23:18:44 +0000137.TP
138.B
njn74e70122005-03-12 21:02:52 +0000139--error-limit=<yes|no> [default: yes]
140When enabled, \fBvalgrind\fP stops reporting errors after 30000 in total,
141or 300 different ones, have been seen. This is to stop the error tracking
142machinery from becoming a huge performance overhead in programs with
143many errors.
njn51272982005-07-25 23:18:44 +0000144
njn74e70122005-03-12 21:02:52 +0000145.TP
146.B
njn74e70122005-03-12 21:02:52 +0000147--gen-suppressions=<yes|no> [default: no]
148When enabled, \fBvalgrind\fP will pause after every error shown and
149print the line:
150
151.PP
152.nf
153.fam C
154 ---- Print suppression ? --- [Return/N/n/Y/y/C/c] ----
155
156.fam T
157.fi
158
159.RS
160Pressing Y Ret or y Ret will cause a suppression for this error to be
161printed. This suppression can be cut-and-paste into a custom suppressions
162file and used to suppress this error in subsequent runs.
163
164.P
165Pressing Ret or n Ret or N Ret will cause no suppression to be printed.
166
167.P
168Pressing C Ret or c Ret will cause no suppression to be printed and
169\fBvalgrind\fP will not ask again.
170.RE
171
172.TP
173.B
174-h --help
175Show help for all options, both for the core and for the selected tool.
176
177.TP
178.B
179--help-debug
180Show help for all options, both for the core and for the selected tool,
181including options for debugging \fBvalgrind\fP.
182
183.TP
184.B
njn51272982005-07-25 23:18:44 +0000185--input-fd=<number> [default: 0, stdin]
186Specify the file descriptor to use for reading input from the user. This
187is used whenever \fBvalgrind\fP needs to prompt the user for a decision.
188
189.TP
190.B
njn74e70122005-03-12 21:02:52 +0000191--log-file=<filename>
192Specifies that \fBvalgrind\fP should send all of its messages to the
193specified file. In fact, the file name used is created by concatenating
194the text filename, ".pid" and the process ID, so as to create a file
195per process. The specified file name may not be the empty string.
196
197.TP
198.B
njn51272982005-07-25 23:18:44 +0000199--log-file-exactly=<filename>
200Just like \fB--log-file\fB, but the ".pid" suffix is not added. If you
201trace multiple processes with Valgrind when using this option the log
202file may get all messed up.
203
204.TP
205.B
206--log-fd=<number> [default: 2, stderr]
207Specifies that \fBvalgrind\fP should send all of its messages to
208the specified file descriptor. The default, 2, is the standard error
209channel (stderr). Note that this may interfere with the client's own
210use of stderr.
211
212.TP
213.B
214--log-file-qualifier=<VAR>
215Specifies that \fBvalgrind\fB should send all of its messages to the
216file named by the environment variable \fB$VAR\fB. This is useful when
217running MPI programs.
218
219.TP
220.B
221--log-socket=<ip-address:port-number>
222Specifies that \fBvalgrind\fP should send all of its messages to the
223specified port at the specified IP address. The port may be omitted,
224in which case port 1500 is used. If a connection cannot be made to
225the specified socket, \fBvalgrind\fP falls back to writing output to
226the standard error (stderr). This option is intended to be used in
227conjunction with the \fBvalgrind-listener\fP program. For further details,
228see section 2.3 of the user manual.
229
230.TP
231.B
njn74e70122005-03-12 21:02:52 +0000232--num-callers=<number> [default=12]
233By default, \fBvalgrind\fP shows 12 levels of function call names to
234help you identify program locations. You can change that number with
235this option. This can help in determining the program's location in
236deeply-nested call chains. Note that errors are commoned up using only
237the top three function locations (the place in the current function,
238and that of its two immediate callers). So this doesn't affect the total
239number of errors reported.
240
241.RS
242.PP
243The maximum value for this is 50. Note that higher settings will make
244\fBvalgrind\fP run a bit more slowly and take a bit more memory, but
245can be useful when working with programs with deeply-nested call chains.
246.RE
247
248.TP
249.B
250-q --quiet
251Run silently, and only print error messages. Useful if you are running
252regression tests or have some other automated test machinery.
253
254.TP
255.B
njn51272982005-07-25 23:18:44 +0000256--show-below-main=<yes|no> [default: no]
257When enabled, this option causes full stack backtraces to be emited,
258including the part before \fBmain\fP in your program (subject to the
259\fB--num-callers\fP option.) When disabled, only the part of the stack
260backtrace up to and including main is printed.
261
262.TP
263.B
njn74e70122005-03-12 21:02:52 +0000264--suppressions=<filename> [default: $PREFIX/lib/\fBvalgrind\fP/default.supp]
265Specifies an extra file from which to read descriptions of errors to
266suppress. You may specify up to 10 additional suppression files.
267
268.TP
269.B
njn51272982005-07-25 23:18:44 +0000270--time-stamp=<yes|no> [default: no]
271When enabled, a time-stamp is added to all log messages.
272
273.TP
274.B
njn74e70122005-03-12 21:02:52 +0000275--tool=<toolname> [default: memcheck]
276Specify which tool to use. The default tool is memcheck.
277
278.TP
279.B
280--trace-children=<yes|no> [default: no]
281When enabled, \fBvalgrind\fP will trace into child processes. This is
282confusing and usually not what you want, so is disabled by default.
283
284.TP
285.B
286--track-fds=<yes|no> [default: no]
287Track file descriptor creation and deletion and produce a summary at the
288end of the program execution of file descriptors that are still in use.
289
290.TP
291.B
292-v --verbose
293Be more verbose. Gives extra information on various aspects of your
294program, such as: the shared objects loaded, the suppressions used,
295the progress of the instrumentation and execution engines, and warnings
296about unusual behaviour. Repeating the flag increases the verbosity level.
297
298.TP
299.B
300--version
301Show the version number of the \fBvalgrind\fP core. Tools can have
302their own version numbers. There is a scheme in place to ensure that
303tools only execute when the core version is one they are known to work
304with. This was done to minimise the chances of strange problems arising
305from tool-vs-core version incompatibilities.
306
307.SH ADDRCHECK OPTIONS
308
309.TP
310.B
311--freelist-vol=<number> [default: 1000000]
312When the client program releases memory using free (in C) or delete
313(C++), that memory is not immediately made available for re-allocation.
314Instead it is marked inaccessible and placed in a queue of freed blocks.
315The purpose is to delay the point at which freed-up memory comes back
316into circulation. This increases the chance that \fBaddrcheck\fP will
317be able to detect invalid accesses to blocks for some significant period
318of time after they have been freed.
319
320.RS
321This flag specifies the maximum total size, in bytes, of the blocks in
322the queue. The default value is one million bytes. Increasing this
323increases the total amount of memory used by \fBaddrcheck\fP but may
324detect invalid uses of freed blocks which would otherwise go undetected.
325.RE
326
327.TP
328.B
329--leak-check=<yes|no|summary|full> [default: summary]
330Enables full, summary or no leak checking. When full (\fBfull\fP or
331\fByes\fP options) checking is performed, details on all leaked blocks
332are printed after the program finishes executing. When summary checking
333is enabled, a summary of all leaked memory is printed. When no leak
334checking is performed, no leaked memory details are produced. Disabling
335leak checking can speed up your program execution.
336
337.TP
338.B
339--leak-resolution=<low|med|high> [default: low]
340When doing leak checking, determines how willing \fBaddrcheck\fP is to
341consider different backtraces to be the same. When set to \fBlow\fP,
342the default, only the first two entries need match. When \fBmed\fP,
343four entries have to match. When \fBhigh\fP, all entries need to match.
344
345.TP
346.B
347--partial-loads-ok=<yes|no> [default: yes]
348Controls how \fBaddrcheck\fP handles word (4-byte) loads from addresses
349for which some bytes are addressible and others are not. When enabled,
350such loads do not elicit an address error. Instead, \fBaddrcheck\fP
351considers the bytes corresponding to the illegal addresses as undefined,
352and those corresponding to legal addresses are considered defined.
353
354.RS
355When disabled, loads from partially invalid addresses are treated the
356same as loads from completely invalid addresses: an illegal-address error
357is issued, and the \fBaddrcheck\fP considers all bytes as invalid data.
358.RE
359
360.TP
361.B
362--show-reachable=<yes|no> [default: no]
363When performing full leak checking, print out details of blocks that are
364leaked but still reachable. For details of what a reachable block is,
365see the HTML documentation.
366
367.TP
368.B
369--workaround-gcc296-bugs=<yes|no> [default: no]
370When enabled, assume that reads and writes some small distance below
371the stack pointer \fB%esp\fP are due to bugs in gcc 2.96, and does not
372report them. The "small distance" is 256 bytes by default. Note that gcc
3732.96 is the default compiler on some older Linux distributions (RedHat
3747.X, Mandrake) and so you may well need to use this flag. Do not use
375it if you do not have to, as it can cause real errors to be overlooked.
376Another option is to use a gcc/g++ which does not generate accesses below
377the stack pointer. 2.95.3 seems to be a good choice in this respect.
378
379.SH MEMCHECK OPTIONS
380\fBmemcheck\fP understands the same options as \fBaddrcheck\fP, along
381with the following options:
382
383.TP
384.B
385--avoid-strlen-errors=<yes|no> [default: yes]
386Enable or disable a heuristic for dealing with highly-optimized versions
387of \fBstrlen\fP. These versions of \fBstrlen\fP can cause spurious
388errors to be reported by \fBmemcheck\fP, so it's usually a good idea to
389leave this enabled.
390
njn74e70122005-03-12 21:02:52 +0000391.SH CACHEGRIND OPTIONS
392
393.TP
394.B
395--D1=<size>,<associativity>,<line size>
396Specify the size, associativity and line size of the level 1 data cache.
397All values are measured in bytes. If this options is not specified,
398the system value (as retrieved by the \fBCPUID\fP instruction) is used.
399
400.TP
401.B
402--I1=<size>,<associativity>,<line size>
403Specify the size, associativity and line size of the level 1 instruction
404cache. All values are measured in bytes. If this options is not
405specified, the system value (as retrieved by the \fBCPUID\fP instruction)
406is used.
407
408.TP
409.B
410--L2=<size>,<associativity>,<line size>
411Specify the size, associativity and line size of the level 2 cache.
412All values are measured in bytes. If this options is not specified,
413the system value (as retrieved by the \fBCPUID\fP instruction) is used.
414
415.SH MASSIF OPTIONS
416
417.TP
418.B
419--alloc-fn=<name>
420Specify a function that allocates memory. This is useful for functions
421that are wrappers to \fBmalloc()\fP, which can fill up the context
422information uselessly (and give very uninformative bands on the graph).
423Functions specified will be ignored in contexts, i.e. treated as though
424they were \fBmalloc()\fP. This option can be specified multiple times
425on the command line, to name multiple functions.
426
427.TP
428.B
429--depth=<number> [default: 3]
430Depth of call chains to present in the detailed heap information.
431Increasing it will give more information, but \fBmassif\fP will run the
432program more slowly, using more memory, and produce a bigger \fB.txt\fP
433or \fB.hp\fP file.
434
435.TP
436.B
437--format=<text|html> [default: text]
438Produce the detailed heap information in text or HTML format. The file
439suffix used will be either \fB.txt\fP or \fB.html\fP.
440
441.TP
442.B
443--heap=<yes|no> [default: yes]
444When enabled, profile heap usage in detail. Without it, the \fB.txt\fP
445or \fB.html\fP file will be very short.
446
447.TP
448.B
449--heap-admin=<number> [default: 8]
450The number of admin bytes per block to use. This can only be an
451estimate of the average, since it may vary. The allocator used
452by \fBglibc\fP requires somewhere between 4 to 15 bytes per block,
453depending on various factors. It also requires admin space for freed
454blocks, although \fBmassif\fP does not count this.
455
456.TP
457.B
458--stacks=<yes|no> [default: yes]
459When enabled, include stack(s) in the profile. Threaded programs can
460have multiple stacks.
461
462." .SH HELGRIND OPTIONS
463
464." .TP
465." .B
466." --private-stacks=<yes|no> [default: no]
467." Assume thread stacks are used privately.
468
469." .TP
470." .B
471." --show-last-access=<yes|some|no> [default: no]
472." Show location of last word access on error.
473
474.SH LESS FREQUENTLY USED CORE OPTIONS
475
476.TP
477.B
478--alignment=<number> [default: 8]
479By default \fBvalgrind\fP's malloc, realloc, etc, return 8-byte aligned
njn51272982005-07-25 23:18:44 +0000480addresses. These are suitable for any accesses on most processors. Some
njn74e70122005-03-12 21:02:52 +0000481programs might however assume that malloc et al return 16- or more
482aligned memory. These programs are broken and should be fixed, but if
483this is impossible for whatever reason the alignment can be increased
484using this parameter. The supplied value must be between 8 and 4096
485inclusive, and must be a power of two.
486
487.TP
488.B
njn74e70122005-03-12 21:02:52 +0000489--pointercheck=<yes|no> [default: yes]
490When enabled, enforces client address space limits. If this option is
491disabled, the client program has full and unfettered access to the part
492of the address space used internally by \fBvalgrind\fP. This can cause
493unexplained crashes and false error reports, so it is best left enabled.
494
495.TP
496.B
497--run-libc-freeres=<yes|no> [default: yes]
498The GNU C library (libc.so), which is used by all programs, may allocate
499memory for its own uses. Usually it doesn't bother to free that memory when
500the program ends - there would be no point, since the Linux kernel reclaims
501all process resources when a process exits anyway, so it would just slow
502things down.
503
504.RS
505.PP
506The glibc authors realised that this behaviour causes leak checkers,
507such as \fBvalgrind\fP, to falsely report leaks in glibc, when a leak
508check is done at exit. In order to avoid this, they provided a routine
509called __libc_freeres specifically to make glibc release all memory it
510has allocated. The MemCheck and AddrCheck tools therefore try and run
511__libc_freeres at exit.
512
513.PP
514Unfortunately, in some versions of glibc, __libc_freeres is sufficiently
515buggy to cause segmentation faults. This is particularly noticeable on
516Red Hat 7.1. So this flag is provided in order to inhibit the run of
517__libc_freeres. If your program seems to run fine on \fBvalgrind\fP, but
518segfaults at exit, you may find that --run-libc-freeres=no fixes that,
519although at the cost of possibly falsely reporting space leaks in libc.so.
520.RE
521
522.TP
523.B
njn74e70122005-03-12 21:02:52 +0000524--weird-hacks=hack1,hack2,\.\.\.
525Pass miscellaneous hints to \fBvalgrind\fP which slightly modify the
526simulated behaviour in nonstandard or dangerous ways, possibly to help
527the simulation of strange features. By default no hacks are enabled. Use
528with caution! Currently known hacks are:
529
530.RS
531.TP
532.B
533- lax-ioctls
534If \fBvalgrind\fP encounters an \fBioctl\fP that it doesn't understand,
535it normally prints a warning message before continuing. Specifying the
536lax-ioctls hack tells \fBvalgrind\fP to be very lax about ioctl handling
537and assume that unknown ioctls just behave correctly.
538.TP
539.B
540- ioctl-mmap
541Tell \fBvalgrind\fP to search for new memory mappings after an unknown
542\fBioctl\fP call.
543.RE
544
545.SH CORE DEBUGGING OPTIONS
546
547.TP
548.B
njn51272982005-07-25 23:18:44 +0000549Valgrind has several debugging options that are mostly of use to developers. Use \fB--help-debug\fB to show them.
njn74e70122005-03-12 21:02:52 +0000550
551.SH SEE ALSO
552/usr/share/doc/\fBvalgrind\fP/html/manual.html
553
554.SH AUTHOR
555This manpage has been written by Andres Roldan <aroldan@debian.org>
556for the Debian Project, but can be used for any other distribution.
557Updated, rearranged and expanded by Robert Walsh <rjwalsh@durables.org>
558for the 2.4.0 release.