Questions tagged [ltrace]

ltrace is a library call tracer. It is a debugging utility in Linux, used to display the calls a userland application makes to shared libraries.

 

Description:

      ltrace is a program that simply runs the specified command until it exits. It intercepts and records the dynamic library calls which are called by the executed process and the signals which are received by that process. It can also intercept and print the system calls executed by the program.

 

Package:

       ltrace

 

Usage:

      Check out the manpage for complete list of options and their usage.

 

Prototype Library Discovery:

      When a library is mapped into the address space of a traced process, ltrace needs to know what the prototypes are of functions that this library implements. For purposes of ltrace, prototype really is a bit more than just type signature: it's also formatting of individual parameters and of return value. These prototypes are stored in files called prototype libraries.

      After a library is mapped, ltrace finds out what its SONAME is. It then looks for a file named SONAME.conf e.g. Prototype library for libc.so.6 would be in a file called libc.so.6.conf. When such file is found, ltrace reads all prototypes stored therein.

  • When a symbol table entry point (such as those traced by -x) is hit, the prototype is looked up in a prototype library corresponding to the library where the hit occurred.
  • When a library call (such as those traced by -e and -l) is hit, the prototype is looked up in all prototype libraries loaded for given process. That is necessary, because a library call is traced in a PLT table of a caller library, but the prototype is described at callee library.

      If a library has no SONAME, basename of library file is considered instead. For the main program binary, basename is considered as well (e.g. prototype library for /bin/echo would be called echo.conf).

      If a name corresponding to soname (e.g. libc.so.6.conf) is not found, and the module under consideration is a shared library, ltrace also tries partial matches. ltrace snips one period after another, retrying the search, until either a protolib is found, or X.so is all that's left. Thus libc.so.conf would be considered, but libc.conf not.

      When looking for a prototype library, ltrace potentially looks into several directories. On Linux, those are $XDG_CONFIG_HOME/ltrace, $HOME/.ltrace, X/ltrace for each X in $XDG_CONFIG_DIRS and /usr/share/ltrace. If the environment variable XDG_CONFIG_HOME is not defined, ltrace looks into $HOME/.config/ltrace instead.

      There's also a mechanism for loading legacy config files. If $HOME/.ltrace.conf exists, it is imported to every loaded prototype library. Similarly for /etc/ltrace.conf. If both exist, both are imported, and $HOME/.ltrace.conf is consulted before /etc/ltrace.conf.

      If -F contains any directories, those are searched in precedence to the above system directories, in the same order in which they are mentioned in -F. Any files passed in -F are imported similarly to above legacy config files, before them.

 

References:

  1. http://man7.org/linux/man-pages/man1/ltrace.1.html
  2. http://en.wikipedia.org/wiki/Ltrace
  3. http://linux.die.net/man/1/ltrace
  4. man ltrace on a Linux machine.
50 questions
4
votes
1 answer

monitor linux dynamic library

I would like to monitor(debug) a linux dynamic library written in C. I want to see when and what parameters are passed to it. The library to monitor 'X', is invoked by another dynamic library 'Y'. Both 'X and 'Y' appear in /proc/pid/maps of the…
user756235
  • 65
  • 3
3
votes
2 answers

Profiling Android applications using ltrace

I need to profile dynamic library calls of android application and have decided to profile using "ltrace" tool for this purpose. I combined "ltrace" tool into android package, then compiled together successfully. It works fine with shell program…
Honggyu Kim
  • 178
  • 1
  • 8
3
votes
1 answer

What is the state of system level tracing in production Linux systems (RH/CentOS and Debian/Ubuntu)?

I'm helping develop an internal cloud infrastructure (OpenStack) to provide our departments with a fully on-premises alternative to AWS/Rackspace/SoftLayer/etc. My boss just relayed a question to me from some internal customer who is asking us to…
Jim Dennis
  • 17,054
  • 13
  • 68
  • 116
3
votes
1 answer

Importance of Kernel level system calls for fork, vfork

When tracing system calls with ltrace for programs with fork, vfork ... it shows to call SYS_Clone system call. Then what is the importance of the SYS_fork, SYS_vfork system call in the kernel. They are for historical purpose?
user567879
  • 5,139
  • 20
  • 71
  • 105
2
votes
1 answer

ltrace prints only two calls

I ran ltrace on a Word processor and opened a sample file, but surprisingly got only two calls. __libc_start_main(0x8048820, 1, 0xbfe08844, 0x8048850, 0x80488b0 _ZN10AP_UnixApp4mainEPKciPPc(0x8048910, 1, 0xbfe08844, 0xb61feff4,…
navgeet
  • 987
  • 1
  • 10
  • 23
2
votes
3 answers

Is there a way to find all the functions used in a c program?

I have the source code for a huge (exaggerated) c program with multiple files. I was hoping if there was any way to find all the functions (both standard and builtin) used (both declared and called) in the program. I know I can compile it and track…
EHM
  • 877
  • 1
  • 7
  • 28
2
votes
0 answers

Cross-compilation of 'ltrace' fails with "error: libelf.h or gelf.h not found in your system" despite it being in /usr/local/include

So I have an x86_64 arch and I need to compile for aarch64 (arm). I have libelf.h and gelf.h in /usr/local/include, which should be automatically included by gcc. I also tried exporting CPPFLAGS=-I/usr/local/include/libelf or using the with-libelf…
2
votes
1 answer

How to make ltrace -S show all arguments of system calls?

I was using ltrace -S to see what system calls dlopen was making but then I noticed that SYS_mmap was limited to only 4 arguments: SYS_mmap(0x7f1c325fe000, 8192, 3, 2066) while it takes a total of 6 arguments. In particular, the file descriptor,…
Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
2
votes
1 answer

ltrace and gdb attach to same process

Is it somehow possible to use ltrace and gdb at the same time? I have a small stripped binary program, where I would like to see the variable contents, of some library calls I can see with ltrace. Is it somehow possible to attach gdb and ltrace to…
Manuel
  • 613
  • 1
  • 6
  • 20
2
votes
1 answer

Why does ltrace show so many parameters and arguments?

It seems like ltrace is showing more parameters then the functions provide, take for instance this getauxval(31, 0x7ffe5ee5a5c0, 0, 0x7066732e6d657473) = 0x7f4f747cd030 Why are there 4 parameters there, two integers two memory locations rather than…
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
2
votes
0 answers

ltrace for Android build

guys. I'm trying to buidl ltrace for Android from this repo https://android.googlesource.com/platform/external/ltrace/ . So i've installed android-ndk, then i've done everything like in android manual for using standalone toolchain for arm and…
Mike R
  • 23
  • 5
2
votes
1 answer

How to use ltrace for mpi programs?

I want to know how to use ltrace to get library function calls of mpi application but simply ltrace doesn't work and my mpirun cannot succeed. Any idea?
Lei
  • 432
  • 2
  • 5
  • 10
2
votes
1 answer

How to use ltrace with wildcards

I'm new to ltrace. I'd like to use wildcards (patterns) to trace function calls, but they don't seem to work as they should, based on the web pages I see, e.g. http://man7.org/linux/man-pages/man1/ltrace.1.html E.g. this works: ltrace -c -e…
tzp
  • 544
  • 7
  • 10
2
votes
2 answers

building ltrace for android

I'm trying to build ltrace for android. I've tryed a few ways none worked.... I was able to produce a bin file compiling the source code using crosstool-ng's arm-unknown-linux-gnueabi and ./configure -host=arm-linux-gnueabi -target…
mfa326
  • 21
  • 2
2
votes
1 answer

ltrace: call nesting error

I am running ltrace -c -C ./a.out to do some profiling of my an application but its giving error as follows: Error: call nesting too deep! my code is very simple as void StrinstrTest(long loop/*4000*/) { std::string s("SS"); double…
CrazyC
  • 1,840
  • 6
  • 39
  • 60