Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to make valgrind ignore certain libraries?

Or preferably all of them instead of just my code? My program uses Gtk, Loudmouth and few other things, and these two (and some behind them, libgcrypto, libssl) are causing so many errors themselves that I'm unable to detect my own. Is it possible to make valgrind ignore things coming from deeper than my own code?

like image 435
tadzik Avatar asked Jul 04 '10 11:07

tadzik


People also ask

What is Valgrind suppression?

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.

What are suppressed errors Valgrind?

Therefore, Valgrind allows you to selectively suppress errors, by recording them in a suppressions file which is read when Valgrind starts up. The build mechanism attempts to select suppressions which give reasonable behaviour for the libc and XFree86 versions detected on your machine.

What is Valgrind used for?

Valgrind Memcheck is a tool that detects memory leaks and memory errors. Some of the most difficult C bugs come from mismanagement of memory: allocating the wrong size, using an uninitialized pointer, accessing memory after it was freed, overrunning a buffer, and so on.

What does Valgrind return?

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).


2 Answers

Assuming you are running the memcheck tool and you want to ignore Leak errors in libcrypto only, you could put a suppression like:

{    ignore_libcrypto_conditional_jump_errors    Memcheck:Leak    ...    obj:*/libcrypto.so.* } 

... into a file and pass it to valgrind with --suppressions=*FILENAME*.

To ignore Leak errors in all shared libraries under any lib directory (/lib, /lib64, /usr/lib, /usr/lib64, ...):

{    ignore_unversioned_libs    Memcheck:Leak    ...    obj:*/lib*/lib*.so } {    ignore_versioned_libs    Memcheck:Leak    ...    obj:*/lib*/lib*.so.* } 

It is unlikely, but you may need to add additional variations of the directory pattern to account for the locations of the X11 and GTK libraries.

Beware that this will ignore errors caused by any callbacks you wrote that were invoked by the libraries. Catching errors in those callbacks could almost be done with:

{    ignore_unversioned_libs    Memcheck:Leak    obj:*/lib*/lib*.so    ...    obj:*/lib*/lib*.so } {    ignore_versioned_libs    Memcheck:Leak    obj:*/lib*/lib*.so.*    ...    obj:*/lib*/lib*.so.* } 

... but this reveals errors in calls by a library that use the Valgrind malloc. Since valgrind malloc is injected directly into the program text -- not loaded as a dynamic library -- it appears in the stack the same way as your own code does. This allows Valgrind to track the allocations, but also makes it harder to do exactly what you have asked.

FYI: I am using valgrind 3.5.

like image 83
mormegil Avatar answered Sep 25 '22 14:09

mormegil


You can generate suppressions for the errors for the libraries, but I don't think you can exclude the libraries generally.

Also it's hard to automatically know if a memory error in the library is caused by a problem in your code or not.

like image 32
Douglas Leeder Avatar answered Sep 23 '22 14:09

Douglas Leeder