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
39
votes
0 answers

Difference between gdb, valgrind, strace, ltrace and apport

I'm looking for the difference between the following debugging tools. What are those? E: On the off chance that somebody stumbles in here and was wondering about the same thing the "differences" are (shortened from the man pages): GDB Allows you to…
Det
  • 3,640
  • 5
  • 20
  • 27
22
votes
3 answers

No output when running ltrace

As the title says, ltrace does not work properly on my system. It shows no output in most cases, like $ltrace ls [usual ls output] +++ exited (status 0) +++ $gcc hello.c $ltrace ./a.out Hello world! +++ exited (status 0) +++ I'm using the latest…
0x5C91
  • 3,360
  • 3
  • 31
  • 46
10
votes
1 answer

Alternative to ltrace that works on binaries linked with `-z now`?

ltrace doesn't work on binaries linked with the -z now option, which is the default on my Ubuntu 19.10 system. It only works on binaries linked with -z lazy. Is there any alternative to ltrace that does the same job, but works on now binaries also?
Sumit Ghosh
  • 1,033
  • 10
  • 29
7
votes
1 answer

How does ltrace (library tracing tool) work?

How does ltrace work? How does it find out which library functions a program calls? Is there any common code path that all calls to library functions go through? Maybe ltrace sets breakpoints in this common code path?
Marko Kevac
  • 2,902
  • 30
  • 47
7
votes
1 answer

ltrace: Couldn't find .dynsym or .dynstr in "library.so"

I have tried to use the ltrace. I tried to use the following command to profile the library.so file which is used by a program sampleapp, ltrace -c -T --library=library.so --output=out.txt ./SampleApp. But it shows the above error. But library.so is…
Tahlil
  • 2,680
  • 6
  • 43
  • 84
6
votes
3 answers

iphone: strace, dtruss, dtrace or equivalent?

Does anyone know if there is something like strace, dtruss, or dtrace for iPhone? tester-iPhone:/tmp root$ apt-cache search dtruss tester-iPhone:/tmp root$ apt-cache search dtrace tester-iPhone:/tmp root$ apt-cache search trace tester-iPhone:/tmp…
osmund sadler
  • 1,021
  • 2
  • 15
  • 27
6
votes
4 answers

Line Number Info in ltrace and strace tools

Is it possible that I can view the line number and file name (for my program running with ltrace/strace) along with the library call/system call information. Eg: code section :: ptr = malloc(sizeof(int)*5); (file:code.c, line:21) ltrace or any…
Sandeep Singh
  • 4,941
  • 8
  • 36
  • 56
6
votes
1 answer

Why is my mprotect function called with 5 arguments?

According to the Linux man page for mprotect the function has 3 arguments: int mprotect(const void *addr, size_t len, int prot); but while running ltrace on a program that I'm analyzing I see that mprotect is called like this: mprotect(0x8049000,…
woolagaroo
  • 1,542
  • 2
  • 22
  • 31
6
votes
1 answer

ltrace doesn't work on some binaries

According to the man page, ltrace is supposed to intercept and record the dynamic library calls on any executed process, however it seems to not work properly on some binaries. Here is the way to reproduce the problem while trying to trace strcpy. I…
Nikhil A R
  • 71
  • 1
  • 4
5
votes
4 answers

What interprocess locking calls should I monitor?

I'm monitoring a process with strace/ltrace in the hope to find and intercept a call that checks, and potentially activates some kind of globally shared lock. While I've dealt with and read about several forms of interprocess locking on Linux…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
4
votes
2 answers

Series of strcmp() calls at the start of simple C++ program

I have a simple C++ program: #include int main() { std::cout << "Hello\n"; return 0; } I was playing with "scratchbox" - cross compilation platform that I use in order to compile applications for ARM platform. I run it…
4
votes
2 answers

How to trace dynamically loaded library calls with ltrace

I have a C program using dynamically loaded library to load plugins. I would like to trace the library calls in order to debug the plugin's loading. I looked at ltrace, but I can't seem to make it work: Here is an example program: #include…
Wenzel
  • 147
  • 1
  • 14
4
votes
3 answers

strace/ltrace outputs inconsistent info

strace pwd: getcwd("/root"..., 4096) = 6 ltrace pwd: getcwd(NULL, 0) = "/root" Why the 1st parameter is NULL in ltrace? It eems strace/ltrace both uses the ptrace syscall,but why they get…
Je Rog
  • 5,675
  • 8
  • 39
  • 47
4
votes
1 answer

How does ltrace() display rand()

When ltrace hits a rand function, it shows it with 4 paramters, like this: rand(0, 0x5649bd4e6010, 0x7f0955490760, 0x7f09551cf7b0) = 0x17382962 rand doesn't take any arguments. What is ltrace showing here? Edited to add…
DCHeel
  • 51
  • 4
4
votes
1 answer

Giving command line arguments to executable being run with ltrace/strace

The title says it all friends! How do I give command line arguments to an executable whose execution I want to monitor using ltrace/strace ? For example, if the executable is 'a.out' and I want to store ltrace's output in a file 'out.txt' and 'arg1'…
Iceflame007
  • 147
  • 2
  • 11
1
2 3 4