Re: trace for shared lib calles ?

Martin von Loewis (
Sat, 26 Jul 1997 09:50:22 +0200

> is there an easy way to trace some/all calls to a shared lib (if possible
> without hacking the lib sources and add warppers there) similar to "strace"
> for system calls ?

I don't think there is. This could be done by creating wrappers

> if there is no such tool/method available, I'd like to write wrapper functions
> which can be preloaded using LD_PPRELOAD which should call the functions
> in he original library then and generaet the "ltrace" output.
> but how do I create e.g. a function "malloc" for the preload/wrapper library
> which then should call "malloc" from the real shared libc without generating
> a recursive call to itself (the wrapper function) ?

You can locate the original symbol using

> PS: for now it would be possible to hack the according lib sources to
> add code (if someone has tools for this for libc or similar...)
> but I'd prefer a binary-only solution to be able to trace libs
> without sources (e.g. libXm.2) too!

If re-linking the application is acceptable, you can also use the
--wrap ld(1) option. You would have to write a function __wrap_malloc,
and it would call __real_malloc inside.

If you are going to do this for a large number of functions, it might
be a good idea to use SWIG, the Simplified Wrapper Interface Generator.

Good luck,

P.S. I don't think this is kernel-related at all.