| Valgrind 3.3 - Advanced Debugging and Profiling for GNU/Linux applications by J. Seward, N. Nethercote, J. Weidendorfer and the Valgrind Development Team Paperback (6"x9"), 164 pages ISBN 0954612051 RRP £12.95 ($19.95) |
3.5 Suppressing errors
The error-checking tools detect numerous problems in the base libraries, such as the GNU C library, and the X11 client libraries, which come pre-installed on your GNU/Linux system. You can't easily fix these, but you don't want to see these errors (and yes, there are many!) So Valgrind reads a list of errors to suppress at startup. A default suppression file is created by the ‘./configure’ script when the system is built.
You can modify and add to the suppressions file at your leisure, or, better, write your own. Multiple suppression files are allowed. This is useful if part of your project contains errors you can't or don't want to fix, yet you don't want to continuously be reminded of them.
Note: By far the easiest way to add
suppressions is to use the --gen-suppressions=yes flag
described in 3.6.
Each error to be suppressed is described very specifically, to minimise the possibility that a suppression-directive inadvertantly suppresses a bunch of similar errors which you did want to see. The suppression mechanism is designed to allow precise yet flexible specification of errors to suppress.
If you use the -v flag, at the end of execution,
Valgrind prints out one line for each used suppression, giving its name
and the number of times it got used. Here's the suppressions used by a
run of ‘valgrind --tool=memcheck ls -l’:
--27579-- supp: 1 socketcall.connect(serv_addr)
/__libc_connect/__nscd_getgrgid_r
--27579-- supp: 1 socketcall.connect(serv_addr)
/__libc_connect/__nscd_getpwuid_r
--27579-- supp: 6 strrchr/_dl_map_object_from_fd
/_dl_map_object
Multiple suppressions files are allowed. By default, Valgrind
uses ‘$PREFIX/lib/valgrind/default.supp’. You can
ask to add suppressions from another file, by specifying
--suppressions=/path/to/file.supp.
If you want to understand more about suppressions, look at an existing suppressions file whilst reading the following documentation. The file ‘glibc-2.3.supp’, in the source distribution, provides some good examples.
Each suppression has the following components:
- First line: its name. This merely gives a handy name to the suppression, by which it is referred to in the summary of used suppressions printed out when a program finishes. It's not important what the name is; any identifying string will do.
-
Second line: name of the tool(s) that the suppression is for
(if more than one, comma-separated), and the name of the suppression
itself, separated by a colon (n.b.: no spaces are allowed), e.g.:
tool_name1,tool_name2:suppression_name
Recall that Valgrind is a modular system, in which different instrumentation tools can observe your program whilst it is running. Since different tools detect different kinds of errors, it is necessary to say which tool(s) the suppression is meaningful to. Tools will complain, at startup, if a tool does not understand any suppression directed to it. Tools ignore suppressions which are not directed to them. As a result, it is quite practical to put suppressions for all tools into the same suppression file. -
Next line: a small number of suppression types have extra
information after the second line (e.g. the
Paramsuppression for Memcheck) -
Remaining lines: This is the calling context for the error--the
chain of function calls that led to it. There can be up to 24
of these lines.
Locations may be either names of shared objects/executables or
wildcards matching function names. They begin
‘obj:’ and
‘fun:’ respectively. Function and
object names to match against may use the wildcard characters
‘*’ and
‘?’.
Important note:C++ function names must bemangled. If you are writing suppressions by hand, use the--demangle=nooption to get the mangled names in your error messages. - Finally, the entire suppression must be between curly braces. Each brace must be the first character on its own line.
A suppression only suppresses an error when the error matches all the details in the suppression. Here's an example:
{
__gconv_transform_ascii_internal/__mbrtowc/mbtowc
Memcheck:Value4
fun:__gconv_transform_ascii_internal
fun:__mbr*toc
fun:mbtowc
}
What it means is: for Memcheck only, suppress a use-of-uninitialised-value error, when the data size is 4, when it occurs in the function ‘__gconv_transform_ascii_internal’, when that is called from any function of name matching ‘__mbr*toc’, when that is called from ‘mbtowc’. It doesn't apply under any other circumstances. The string by which this suppression is identified to the user is ‘__gconv_transform_ascii_internal/__mbrtowc/mbtowc’.
(See 5.4 for more details on the specifics of Memcheck's suppression kinds.)
Another example, again for the Memcheck tool:
{
libX11.so.6.2/libX11.so.6.2/libXaw.so.7.0
Memcheck:Value4
obj:/usr/X11R6/lib/libX11.so.6.2
obj:/usr/X11R6/lib/libX11.so.6.2
obj:/usr/X11R6/lib/libXaw.so.7.0
}
Suppress any size 4 uninitialised-value error which occurs anywhere in ‘libX11.so.6.2’, when called from anywhere in the same library, when called from anywhere in ‘libXaw.so.7.0’. The inexact specification of locations is regrettable, but is about all you can hope for, given that the X11 libraries shipped on the Linux distro on which this example was made have had their symbol tables removed.
Although the above two examples do not make this clear, you can freely mix ‘obj:’ and ‘fun:’ lines in a suppression.
| ISBN 0954612051 | Valgrind 3.3 - Advanced Debugging and Profiling for GNU/Linux applications | See the print edition |