man valgrind Command

Man page for apt-get valgrind Command

Man Page for valgrind in Linux

Ubuntu Man Command : man valgrind

Man Valgrind  Command

This tutorial shows the man page for man valgrind in linux.

Open terminal with 'su' access and type the command as shown below:
man valgrind

Result of the Command Execution shown below:

VALGRIND(1)                      Release 3.5.0                     VALGRIND(1)

valgrind a suite of tools for debugging and profiling programs

valgrind [valgrind options] [your program] [your program options]

Valgrind is a flexible program for debugging and profiling Linux
executables. It consists of a core, which provides a synthetic CPU in
software, and a series of debugging and profiling tools. The
architecture is modular, so that new tools can be created easily and
without disturbing the existing structure.

Some of the options described below work with all Valgrind tools, and
some only work with a few or one. The section MEMCHECK OPTIONS and
those below it describe tool specific options.

This manual page covers only basic usage and options. For more
comprehensive information, please see the HTML documentation on your
system: $INSTALL/share/doc/valgrind/html/index.html, or online:

These options work with all tools.

h help
Show help for all options, both for the core and for the selected

help debug
Same as help, but also lists debugging options which usually are
only of use to Valgrind's developers.

Show the version number of the Valgrind core. Tools can have their
own version numbers. There is a scheme in place to ensure that
tools only execute when the core version is one they are known to
work with. This was done to minimise the chances of strange
problems arising from tool vs core version incompatibilities.

q, quiet
Run silently, and only print error messages. Useful if you are
running regression tests or have some other automated test

v, verbose
Be more verbose. Gives extra information on various aspects of your
program, such as: the shared objects loaded, the suppressions used,
the progress of the instrumentation and execution engines, and
warnings about unusual behaviour. Repeating the option increases
the verbosity level.

trace children= [default: no]
When enabled, Valgrind will trace into sub processes initiated via
the exec system call. This is necessary for multi process programs.

Note that Valgrind does trace into the child of a fork (it would be
difficult not to, since fork makes an identical copy of a process),
so this option is arguably badly named. However, most children of
fork calls immediately call exec anyway.

trace children skip=patt1,patt2
This option only has an effect when trace children=yes is
specified. It allows for some children to be skipped. The option
takes a comma separated list of patterns for the names of child
executables that Valgrind should not trace into. Patterns may
include the metacharacters ? and *, which have the usual meaning.

This can be useful for pruning uninteresting branches from a tree
of processes being run on Valgrind. But you should be careful when
using it. When Valgrind skips tracing into an executable, it
doesn't just skip tracing that executable, it also skips tracing
any of that executable's child processes. In other words, the flag
doesn't merely cause tracing to stop at the specified executables
it skips tracing of entire process subtrees rooted at any of the
specified executables.

child silent after fork= [default: no]
When enabled, Valgrind will not show any debugging or logging
output for the child process resulting from a fork call. This can
make the output less confusing (although more misleading) when
dealing with processes that create children. It is particularly
useful in conjunction with trace children=. Use of this option is
also strongly recommended if you are requesting XML output
( xml=yes), since otherwise the XML from child and parent may
become mixed up, which usually makes it useless.

track fds= [default: no]
When enabled, Valgrind will print out a list of open file
descriptors on exit. Along with each file descriptor is printed a
stack backtrace of where the file was opened and any details
relating to the file descriptor such as the file name or socket

time stamp= [default: no]
When enabled, each message is preceded with an indication of the
elapsed wallclock time since startup, expressed as days, hours,
minutes, seconds and milliseconds.

log fd= [default: 2, stderr]
Specifies that Valgrind should send all of its messages to the
specified file descriptor. The default, 2, is the standard error
channel (stderr). Note that this may interfere with the client's
own use of stderr, as Valgrind's output will be interleaved with
any output that the client sends to stderr.

log file=
Specifies that Valgrind should send all of its messages to the
specified file. If the file name is empty, it causes an abort.
There are three special format specifiers that can be used in the
file name.

%p is replaced with the current process ID. This is very useful for
program that invoke multiple processes. WARNING: If you use
trace children=yes and your program invokes multiple processes OR
your program forks without calling exec afterwards, and you don't
use this specifier (or the %q specifier below), the Valgrind output
from all those processes will go into one file, possibly jumbled
up, and possibly incomplete.

%q{FOO} is replaced with the contents of the environment variable
FOO. If the {FOO} part is malformed, it causes an abort. This
specifier is rarely needed, but very useful in certain
circumstances (eg. when running MPI programs). The idea is that you
specify a variable which will be set differently for each process
in the job, for example BPROC_RANK or whatever is applicable in
your MPI setup. If the named environment variable is not set, it
causes an abort. Note that in some shells, the { and } characters
may need to be escaped with a backslash.

%% is replaced with %.

If an % is followed by any other character, it causes an abort.

log socket=
Specifies that Valgrind should send all of its messages to the
specified port at the specified IP address. The port may be
omitted, in which case port 1500 is used. If a connection cannot be
made to the specified socket, Valgrind falls back to writing output
to the standard error (stderr). This option is intended to be used
in conjunction with the valgrind listener program. For further
details, see the commentary in the manual.

These options are used by all tools that can report errors, e.g.
Memcheck, but not Cachegrind.

xml= [default: no]
When enabled, the important parts of the output (e.g. tool error
messages) will be in XML format rather than plain text.
Furthermore, the XML output will be sent to a different output
channel than the plain text output. Therefore, you also must use
one of xml fd, xml file or xml socket to specify where the
XML is to be sent.

Less important messages will still be printed in plain text, but
because the XML output and plain text output are sent to different
output channels (the destination of the plain text output is still
controlled by log fd, log file and log socket) this should
not cause problems.

This option is aimed at making life easier for tools that consume
Valgrind's output as input, such as GUI front ends. Currently this
option works with Memcheck, Helgrind and Ptrcheck. The output
format is specified in the file
docs/internals/xml output protocol4.txt in the source tree for
Valgrind 3.5.0 or later.

The recommended options for a GUI to pass, when requesting XML
output, are: xml=yes to enable XML output, xml file to send the
XML output to a (presumably GUI selected) file, log file to send
the plain text output to a second GUI selected file,
child silent after fork=yes, and q to restrict the plain text
output to critical error messages created by Valgrind itself. For
example, failure to read a specified suppressions file counts as a
critical error message. In this way, for a successful run the text
output file will be empty. But if it isn't empty, then it will
contain important information which the GUI user should be made
aware of.

xml fd= [default: 1, disabled]
Specifies that Valgrind should send its XML output to the specified
file descriptor. It must be used in conjunction with xml=yes.

xml file=
Specifies that Valgrind should send its XML output to the specified
file. It must be used in conjunction with xml=yes. Any %p or %q
sequences appearing in the filename are expanded in exactly the
same way as they are for log file. See the description of
log file for details.

xml socket=
Specifies that Valgrind should send its XML output the specified
port at the specified IP address. It must be used in conjunction
with xml=yes. The form of the argument is the same as that used
by log socket. See the description of log socket for further

xml user comment=
Embeds an extra user comment string at the start of the XML output.
Only works when xml=yes is specified; ignored otherwise.

demangle= [default: yes]
Enable/disable automatic demangling (decoding) of C++ names.
Enabled by default. When enabled, Valgrind will attempt to
translate encoded C++ names back to something approaching the
original. The demangler handles symbols mangled by g++ versions
2.X, 3.X and 4.X.

An important fact about demangling is that function names mentioned
in suppressions files should be in their mangled form. Valgrind
does not demangle function names when searching for applicable
suppressions, because to do otherwise would make suppression file
contents dependent on the state of Valgrind's demangling machinery,
and also slow down suppression matching.

num callers= [default: 12]
Specifies the maximum number of entries shown in stack traces that
identify program locations. Note that errors are commoned up using
only the top four function locations (the place in the current
function, and that of its three immediate callers). So this doesn't
affect the total number of errors reported.

The maximum value for this is 50. Note that higher settings will
make Valgrind run a bit more slowly and take a bit more memory, but
can be useful when working with programs with deeply nested call

error limit= [default: yes]
When enabled, Valgrind stops reporting errors after 10,000,000 in
total, or 1,000 different ones, have been seen. This is to stop the
error tracking machinery from becoming a huge performance overhead
in programs with many errors.

error exitcode= [default: 0]
Specifies an alternative exit code to return if Valgrind reported
any errors in the run. When set to the default value (zero), the
return value from Valgrind will always be the return value of the
process being simulated. When set to a nonzero value, that value is
returned instead, if Valgrind detects any errors. This is useful
for using Valgrind as part of an automated test suite, since it
makes it easy to detect test cases for which Valgrind has reported
errors, just by inspecting return codes.

show below main= [default: no]
By default, stack traces for errors do not show any functions that
appear beneath main because most of the time it's uninteresting C
library stuff and/or gobbledygook. Alternatively, if main is not
present in the stack trace, stack traces will not show any
functions below main like functions such as glibc's
__libc_start_main. Furthermore, if main like functions are present
in the trace, they are normalised as (below main), in order to make
the output more deterministic.

If this option is enabled, all stack trace entries will be shown
and main like functions will not be normalised.

suppressions= [default: $PREFIX/lib/valgrind/default.supp]
Specifies an extra file from which to read descriptions of errors
to suppress. You may use up to 100 extra suppression files.

gen suppressions= [default: no]
When set to yes, Valgrind will pause after every error shown and
print the line:

Print suppression ? [Return/N/n/Y/y/C/c]

The prompt's behaviour is the same as for the db attach option
(see below).

If you choose to, Valgrind will print out a suppression for this
error. You can then cut and paste it into a suppression file if you
don't want to hear about the error in the future.

When set to all, Valgrind will print a suppression for every
reported error, without querying the user.

This option is particularly useful with C++ programs, as it prints
out the suppressions with mangled names, as required.

Note that the suppressions printed are as specific as possible. You
may want to common up similar ones, by adding wildcards to function
names, and by using frame level wildcards. The wildcarding
facilities are powerful yet flexible, and with a bit of careful
editing, you may be able to suppress a whole family of related
errors with only a few suppressions.

Sometimes two different errors are suppressed by the same
suppression, in which case Valgrind will output the suppression
more than once, but you only need to have one copy in your
suppression file (but having more than one won't cause problems).
Also, the suppression name is given as here>; the name doesn't really matter, it's only used with the v
option which prints out all used suppression records.

db attach= [default: no]
When enabled, Valgrind will pause after every error shown and print
the line:

Attach to debugger ? [Return/N/n/Y/y/C/c]

Pressing Ret, or N Ret or n Ret, causes Valgrind not to start a
debugger for this error.

Pressing Y Ret or y Ret causes Valgrind to start a debugger for the
program at this point. When you have finished with the debugger,
quit from it, and the program will continue. Trying to continue
from inside the debugger doesn't work.

C Ret or c Ret causes Valgrind not to start a debugger, and not to
ask again.

db command= [default: gdb nw %f %p]
Specify the debugger to use with the db attach command. The
default debugger is GDB. This option is a template that is expanded
by Valgrind at runtime. %f is replaced with the executable's file
name and %p is replaced by the process ID of the executable.

This specifies how Valgrind will invoke the debugger. By default it
will use whatever GDB is detected at build time, which is usually
/usr/bin/gdb. Using this command, you can specify some alternative
command to invoke the debugger you want to use.

The command string given can include one or instances of the %p and
%f expansions. Each instance of %p expands to the PID of the
process to be debugged and each instance of %f expands to the path
to the executable for the process to be debugged.

Since is likely to contain spaces, you will need to put
this entire option in quotes to ensure it is correctly handled by
the shell.

input fd= [default: 0, stdin]
When using db attach=yes or gen suppressions=yes, Valgrind will
stop so as to read keyboard input from you when each error occurs.
By default it reads from the standard input (stdin), which is
problematic for programs which close stdin. This option allows you
to specify an alternative file descriptor from which to read input.

dsymutil=no|yes [no]
This option is only relevant when running Valgrind on Mac OS X.

Mac OS X uses a deferred debug information (debuginfo) linking
scheme. When object files containing debuginfo are linked into a
.dylib or an executable, the debuginfo is not copied into the final
file. Instead, the debuginfo must be linked manually by running
dsymutil, a system provided utility, on the executable or .dylib.
The resulting combined debuginfo is placed in a directory alongside
the executable or .dylib, but with the extension .dSYM.

With dsymutil=no, Valgrind will detect cases where the .dSYM
directory is either missing, or is present but does not appear to
match the associated executable or .dylib, most likely because it
is out of date. In these cases, Valgrind will print a warning
message but take no further action.

With dsymutil=yes, Valgrind will, in such cases, automatically
run dsymutil as necessary to bring the debuginfo up to date. For
all practical purposes, if you always use dsymutil=yes, then
there is never any need to run dsymutil manually or as part of your
applications's build system, since Valgrind will run it as

Valgrind will not attempt to run dsymutil on any executable or
library in /usr/, /bin/, /sbin/, /opt/, /sw/, /System/, /Library/
or /Applications/ since dsymutil will always fail in such
situations. It fails both because the debuginfo for such
pre installed system components is not available anywhere, and also
because it would require write privileges in those directories.

Be careful when using dsymutil=yes, since it will cause
pre existing .dSYM directories to be silently deleted and
re created. Also note the dsymutil is quite slow, sometimes
excessively so.

max stackframe= [default: 2000000]
The maximum size of a stack frame. If the stack pointer moves by
more than this amount then Valgrind will assume that the program is
switching to a different stack.

You may need to use this option if your program has large
stack allocated arrays. Valgrind keeps track of your program's
stack pointer. If it changes by more than the threshold amount,
Valgrind assumes your program is switching to a different stack,
and Memcheck behaves differently than it would for a stack pointer
change smaller than the threshold. Usually this heuristic works
well. However, if your program allocates large structures on the
stack, this heuristic will be fooled, and Memcheck will
subsequently report large numbers of invalid stack accesses. This
option allows you to change the threshold to a different value.

You should only consider use of this option if Valgrind's debug
output directs you to do so. In that case it will tell you the new
threshold you should specify.

In general, allocating large structures on the stack is a bad idea,
because you can easily run out of stack space, especially on
systems with limited memory or which expect to support large
numbers of threads each with a small stack, and also because the
error checking performed by Memcheck is more effective for
heap allocated data than for stack allocated data. If you have to
use this option, you may wish to consider rewriting your code to
allocate on the heap rather than on the stack.

main stacksize= [default: use current 'ulimit' value]
Specifies the size of the main thread's stack.

To simplify its memory management, Valgrind reserves all required
space for the main thread's stack at startup. That means it needs
to know the required stack size at startup.

By default, Valgrind uses the current "ulimit" value for the stack
size, or 16 MB, whichever is lower. In many cases this gives a
stack size in the range 8 to 16 MB, which almost never overflows
for most applications.

If you need a larger total stack size, use main stacksize to
specify it. Only set it as high as you need, since reserving far
more space than you need (that is, hundreds of megabytes more than
you need) constrains Valgrind's memory allocators and may reduce
the total amount of memory that Valgrind can use. This is only
really of significance on 32 bit machines.

On Linux, you may request a stack of size up to 2GB. Valgrind will
stop with a diagnostic message if the stack cannot be allocated. On
AIX5 the allowed stack size is restricted to 128MB.

main stacksize only affects the stack size for the program's
initial thread. It has no bearing on the size of thread stacks, as
Valgrind does not allocate those.

You may need to use both main stacksize and max stackframe
together. It is important to understand that main stacksize sets
the maximum total stack size, whilst max stackframe specifies the
largest size of any one stack frame. You will have to work out the
main stacksize value for yourself (usually, if your applications
segfaults). But Valgrind will tell you the needed max stackframe
size, if necessary.

As discussed further in the description of max stackframe, a
requirement for a large stack is a sign of potential portability
problems. You are best advised to place all large data in
heap allocated memory.

For tools that use their own version of malloc (e.g. Memcheck and
Massif), the following options apply.

alignment= [default: 8 or 16, depending on the platform]
By default Valgrind's malloc, realloc, etc, return a block whose
starting address is 8 byte aligned or 16 byte aligned (the value
depends on the platform and matches the platform default). This
option allows you to specify a different alignment. The supplied
value must be greater than or equal to the default, less than or
equal to 4096, and must be a power of two.

These options apply to all tools, as they affect certain obscure
workings of the Valgrind core. Most people won't need to use these.

smc check= [default: stack]
This option controls Valgrind's detection of self modifying code.
If no checking is done, if a program executes some code, then
overwrites it with new code, and executes the new code, Valgrind
will continue to execute the translations it made for the old code.
This will likely lead to incorrect behaviour and/or crashes.

Valgrind has three levels of self modifying code detection: no
detection, detect self modifying code on the stack (which used by
GCC to implement nested functions), or detect self modifying code
everywhere. Note that the default option will catch the vast
majority of cases. The main case it will not catch is programs such
as JIT compilers that dynamically generate code and subsequently
overwrite part or all of it. Running with all will slow Valgrind
down greatly. Running with none will rarely speed things up, since
very little code gets put on the stack for most programs. The
VALGRIND_DISCARD_TRANSLATIONS client request is an alternative to
smc check=all that requires more effort but is much faster.

Some architectures (including ppc32 and ppc64) require programs
which create code at runtime to flush the instruction cache in
between code generation and first use. Valgrind observes and
honours such instructions. Hence, on ppc32/Linux and ppc64/Linux,
Valgrind always provides complete, transparent support for
self modifying code. It is only on platforms such as x86/Linux,
AMD64/Linux and x86/Darwin that you need to use this option.

read var info= [default: no]
When enabled, Valgrind will read information about variable types
and locations from DWARF3 debug info. This slows Valgrind down and
makes it use more memory, but for the tools that can take advantage
of it (Memcheck, Helgrind, DRD) it can result in more precise error
messages. For example, here are some standard errors issued by

==15516== Uninitialised byte(s) found during client check request
==15516== at 0x400633: croak (varinfo1.c:28)
==15516== by 0x4006B2: main (varinfo1.c:55)
==15516== Address 0x60103b is 7 bytes inside data symbol "global_i2"
==15516== Uninitialised byte(s) found during client check request
==15516== at 0x400633: croak (varinfo1.c:28)
==15516== by 0x4006BC: main (varinfo1.c:56)
==15516== Address 0x7fefffefc is on thread 1's stack

And here are the same errors with read var info=yes:

==15522== Uninitialised byte(s) found during client check request
==15522== at 0x400633: croak (varinfo1.c:28)
==15522== by 0x4006B2: main (varinfo1.c:55)
==15522== Location 0x60103b is 0 bytes inside global_i2[7],
==15522== a global variable declared at varinfo1.c:41
==15522== Uninitialised byte(s) found during client check request
==15522== at 0x400633: croak (varinfo1.c:28)
==15522== by 0x4006BC: main (varinfo1.c:56)
==15522== Location 0x7fefffefc is 0 bytes inside local var "local"
==15522== declared at varinfo1.c:46, in frame

Related Topics

Apt Get Commands