These options are used by all tools that can report errors, e.g.
Memcheck, but not Cachegrind.
--xml=<yes|no> [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 DRD.
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=<number> [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=<filename>
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=<ip-address:port-number>
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 details.
--xml-user-comment=<string>
Embeds an extra user comment string at the start of the XML
output. Only works when --xml=yes
is specified; ignored
otherwise.
--demangle=<yes|no> [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=<number> [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 500. 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 chains.
--unw-stack-scan-thresh=<number> [default: 0]
,
--unw-stack-scan-frames=<number> [default: 5]
Stack-scanning support is available only on ARM targets.
These flags enable and control stack unwinding by stack
scanning. When the normal stack unwinding mechanisms -- usage
of Dwarf CFI records, and frame-pointer following -- fail,
stack scanning may be able to recover a stack trace.
Note that stack scanning is an imprecise, heuristic mechanism
that may give very misleading results, or none at all. It
should be used only in emergencies, when normal unwinding
fails, and it is important to nevertheless have stack traces.
Stack scanning is a simple technique: the unwinder reads
words from the stack, and tries to guess which of them might
be return addresses, by checking to see if they point just
after ARM or Thumb call instructions. If so, the word is
added to the backtrace.
The main danger occurs when a function call returns, leaving
its return address exposed, and a new function is called, but
the new function does not overwrite the old address. The
result of this is that the backtrace may contain entries for
functions which have already returned, and so be very
confusing.
A second limitation of this implementation is that it will
scan only the page (4KB, normally) containing the starting
stack pointer. If the stack frames are large, this may result
in only a few (or not even any) being present in the trace.
Also, if you are unlucky and have an initial stack pointer
near the end of its containing page, the scan may miss all
interesting frames.
By default stack scanning is disabled. The normal use case is
to ask for it when a stack trace would otherwise be very
short. So, to enable it, use --unw-stack-scan-thresh=number.
This requests Valgrind to try using stack scanning to
"extend" stack traces which contain fewer than number frames.
If stack scanning does take place, it will only generate at
most the number of frames specified by
--unw-stack-scan-frames. Typically, stack scanning generates
so many garbage entries that this value is set to a low value
(5) by default. In no case will a stack trace larger than the
value specified by --num-callers be created.
--error-limit=<yes|no> [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=<number> [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.
--exit-on-first-error=<yes|no> [default: no]
If this option is enabled, Valgrind exits on the first error.
A nonzero exit value must be defined using --error-exitcode
option. Useful if you are running regression tests or have
some other automated test machinery.
--error-markers=<begin>,<end> [default: none]
When errors are output as plain text (i.e. XML not used),
--error-markers
instructs to output a line containing the
begin
(end
) string before (after) each error.
Such marker lines facilitate searching for errors and/or
extracting errors in an output file that contain valgrind
errors mixed with the program output.
Note that empty markers are accepted. So, only using a begin
(or an end) marker is possible.
--show-error-list=no|yes [default: no]
If this option is enabled, for tools that report errors,
valgrind will show the list of detected errors and the list
of used suppressions at exit.
Note that at verbosity 2 and above, valgrind automatically
shows the list of detected errors and the list of used
suppressions at exit, unless --show-error-list=no
is
selected.
-s
Specifying -s
is equivalent to --show-error-list=yes
.
--sigill-diagnostics=<yes|no> [default: yes]
Enable/disable printing of illegal instruction diagnostics.
Enabled by default, but defaults to disabled when --quiet
is
given. The default can always be explicitly overridden by
giving this option.
When enabled, a warning message will be printed, along with
some diagnostics, whenever an instruction is encountered that
Valgrind cannot decode or translate, before the program is
given a SIGILL signal. Often an illegal instruction indicates
a bug in the program or missing support for the particular
instruction in Valgrind. But some programs do deliberately
try to execute an instruction that might be missing and trap
the SIGILL signal to detect processor features. Using this
flag makes it possible to avoid the diagnostic output that
you would otherwise get in such cases.
--keep-debuginfo=<yes|no> [default: no]
When enabled, keep ("archive") symbols and all other
debuginfo for unloaded code. This allows saved stack traces
to include file/line info for code that has been dlclose'd
(or similar). Be careful with this, since it can lead to
unbounded memory use for programs which repeatedly load and
unload shared objects.
Some tools and some functionalities have only limited support
for archived debug info. Memcheck fully supports it.
Generally, tools that report errors can use archived debug
info to show the error stack traces. The known limitations
are: Helgrind's past access stack trace of a race condition
is does not use archived debug info. Massif (and more
generally the xtree Massif output format) does not make use
of archived debug info. Only Memcheck has been (somewhat)
tested with --keep-debuginfo=yes
, so other tools may have
unknown limitations.
--show-below-main=<yes|no> [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.
--fullpath-after=<string> [default: don't show source paths]
By default Valgrind only shows the filenames in stack traces,
but not full paths to source files. When using Valgrind in
large projects where the sources reside in multiple different
directories, this can be inconvenient. --fullpath-after
provides a flexible solution to this problem. When this
option is present, the path to each source file is shown,
with the following all-important caveat: if string
is found
in the path, then the path up to and including string
is
omitted, else the path is shown unmodified. Note that string
is not required to be a prefix of the path.
For example, consider a file named
/home/janedoe/blah/src/foo/bar/xyzzy.c. Specifying
--fullpath-after=/home/janedoe/blah/src/
will cause Valgrind
to show the name as foo/bar/xyzzy.c.
Because the string is not required to be a prefix,
--fullpath-after=src/
will produce the same output. This is
useful when the path contains arbitrary machine-generated
characters. For example, the path
/my/build/dir/C32A1B47/blah/src/foo/xyzzy can be pruned to
foo/xyzzy using --fullpath-after=/blah/src/
.
If you simply want to see the full path, just specify an
empty string: --fullpath-after=
. This isn't a special case,
merely a logical consequence of the above rules.
Finally, you can use --fullpath-after
multiple times. Any
appearance of it causes Valgrind to switch to producing full
paths and applying the above filtering rule. Each produced
path is compared against all the --fullpath-after
-specified
strings, in the order specified. The first string to match
causes the path to be truncated as described above. If none
match, the full path is shown. This facilitates chopping off
prefixes when the sources are drawn from a number of
unrelated directories.
--extra-debuginfo-path=<path> [default: undefined and unused]
By default Valgrind searches in several well-known paths for
debug objects, such as /usr/lib/debug/.
However, there may be scenarios where you may wish to put
debug objects at an arbitrary location, such as external
storage when running Valgrind on a mobile device with limited
local storage. Another example might be a situation where you
do not have permission to install debug object packages on
the system where you are running Valgrind.
In these scenarios, you may provide an absolute path as an
extra, final place for Valgrind to search for debug objects
by specifying --extra-debuginfo-path=/path/to/debug/objects
.
The given path will be prepended to the absolute path name of
the searched-for object. For example, if Valgrind is looking
for the debuginfo for /w/x/y/zz.so and
--extra-debuginfo-path=/a/b/c
is specified, it will look for
a debug object at /a/b/c/w/x/y/zz.so.
This flag should only be specified once. If it is specified
multiple times, only the last instance is honoured.
--debuginfo-server=ipaddr:port [default: undefined and unused]
This is a new, experimental, feature introduced in version
3.9.0.
In some scenarios it may be convenient to read debuginfo from
objects stored on a different machine. With this flag,
Valgrind will query a debuginfo server running on ipaddr and
listening on port port, if it cannot find the debuginfo
object in the local filesystem.
The debuginfo server must accept TCP connections on port
port. The debuginfo server is contained in the source file
auxprogs/valgrind-di-server.c. It will only serve from the
directory it is started in. port defaults to 1500 in both
client and server if not specified.
If Valgrind looks for the debuginfo for /w/x/y/zz.so by using
the debuginfo server, it will strip the pathname components
and merely request zz.so on the server. That in turn will
look only in its current working directory for a matching
debuginfo object.
The debuginfo data is transmitted in small fragments (8 KB)
as requested by Valgrind. Each block is compressed using LZO
to reduce transmission time. The implementation has been
tuned for best performance over a single-stage 802.11g (WiFi)
network link.
Note that checks for matching primary vs debug objects, using
GNU debuglink CRC scheme, are performed even when using the
debuginfo server. To disable such checking, you need to also
specify --allow-mismatched-debuginfo=yes.
By default the Valgrind build system will build
valgrind-di-server for the target platform, which is almost
certainly not what you want. So far we have been unable to
find out how to get automake/autoconf to build it for the
build platform. If you want to use it, you will have to
recompile it by hand using the command shown at the top of
auxprogs/valgrind-di-server.c.
Valgrind can also download debuginfo via debuginfod. See the
DEBUGINFOD section for more information.
--allow-mismatched-debuginfo=no|yes [no]
When reading debuginfo from separate debuginfo objects,
Valgrind will by default check that the main and debuginfo
objects match, using the GNU debuglink mechanism. This
guarantees that it does not read debuginfo from out of date
debuginfo objects, and also ensures that Valgrind can't crash
as a result of mismatches.
This check can be overridden using
--allow-mismatched-debuginfo=yes. This may be useful when the
debuginfo and main objects have not been split in the proper
way. Be careful when using this, though: it disables all
consistency checking, and Valgrind has been observed to crash
when the main and debuginfo objects don't match.
--suppressions=<filename> [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=<yes|no|all> [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] ----
Pressing Ret, or N Ret or n Ret, causes Valgrind continue
execution without printing a suppression for this error.
Pressing Y Ret or y Ret causes Valgrind to write 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
<insert a suppression name here>; the name doesn't really
matter, it's only used with the -v
option which prints out
all used suppression records.
--input-fd=<number> [default: 0, stdin]
When using --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 [yes]
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 necessary.
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 that dsymutil is quite slow, sometimes
excessively so.
--max-stackframe=<number> [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=<number> [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.
--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.
--max-threads=<number> [default: 500]
By default, Valgrind can handle to up to 500 threads.
Occasionally, that number is too small. Use this option to
provide a different limit. E.g. --max-threads=3000.