[lttng-dev] LTTng-UST alternative to LD_PRELOAD

Woegerer, Paul Paul_Woegerer at mentor.com
Thu Jul 19 03:26:54 EDT 2012


On 06/17/2012 05:08 PM, Lars wrote:
> Hello,
>
> I have recently started to use LTTng-UST and am using LD_PRELOAD
> to make it possilbe to execute instrumented code on systems without
> LTTng-UST installed.
>
> To define LD_PRELOAD however affects too much. For instance all
> forked processes also get the library loaded. This can be fixed by
> removing the library from the LD_PRELOAD variable early in the main
> function. This looks odd and required some explaining in comments.
>
> Also, in my case, the instrumented program is started with a "wrapper"
> program which I can not alter. This wrapper also gets the library
> loaded.
>
> As an alternative to using LD_PRELOAD I would like to use an explicit
> function, like;
>
>    int traceload(char const* library_path);
>
> that is called early in main (instead of the LD_PRELOAD environment
> manipulation) and loads the library with dlopen if it exists.
>
> I have already tried this (of course) and it almost works already.
> The tracepoints becomes visible but I get no trace data written.
> So I think a really small modification is needed.

Another alternative would be to implement an lttng-backend for latrace ( 
see: http://people.redhat.com/jolsa/latrace/index.shtml ).

Library calls from the following headers are supported as of version 
0.5.11:

ctype.h   dlfcn.h  getopt.h  ioctl.h    libintl.h  locale.h  mman.h netdb.h   pwd.h    signal.h  stat.h     stdlib.h   sysdeps   term.h time.h    unistd.h wait.h    dirent.h   fcntl.h    inet.h    latrace.h libio.h   misc.h   ncurses.h pthread.h  resource.h socket.h  stdio.h string.h  syslog.h termios.h typedefs.h utmp.h

So if we let latrace optionally emit lttng events for call enter and exit we would instantly get support for tracing for _any_ library call.

--
Paul

-- 
Paul Woegerer | SW Development Engineer
Mentor Embedded(tm) | Prinz Eugen Straße 72/2/4, Vienna, 1040 Austria
P 43.1.535991320
Nucleus® | Linux® | Android(tm) | Services | UI | Multi-OS

Android is a trademark of Google Inc. Use of this trademark is subject to Google Permissions.
Linux is the registered trademark of Linus Torvalds in the U.S. and other countries.




More information about the lttng-dev mailing list