I have a process that uses dlopen and dlclose to load/unload a library. The library has some memory leaks which I want to trace with Valgrind. I tried the following:
LD_PRELOAD=libmylibrary.so valgrind --leak-check=full myprogram
It doesn't work. I get an undefined symbol error because the library depends on some symbols from the main program. Is there any other way to make the library stay loaded at the end of the program?
This is an old question, but I believe this can help someone in the future if he/she stumbles upon it.
You can pass --keep-debuginfo=yes parameter to valgrind:
--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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With