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
2
votes
2 answers

how can I get C++ heap allocated virtual method names from ltrace?

I've been struggling with this for about a day now. I was able to construct a trivial shared library and test program, which when I run it under ltrace control I can get the method names as expected, for static, virtual and pure virtual methods. I…
1
vote
1 answer

Couldn't find .dynsym while use ltrace

I have tried to attach to process(pid=1234) to watch all libraries call. ./ltrace-arm-static-0.7.91 -fp 1234 I got error: Couldn't find .dynsym or .dynstr in "/proc/1234/exe" What can I do?
Kokomelom
  • 143
  • 1
  • 10
1
vote
0 answers

What could be the interpretation of these strace outputs?

I have a problem with a calculus software in Linux (Ubuntu 20.04). When I submit a calculus, the work is performed perfectly. The log file indicates that everything was completed successfully and all the results are perfect. The problem arises when…
1
vote
0 answers

Why can't strace or ltrace intercept the rand function

I'm using the following C program as an example :: #include #include #include int main(int argc, char const *argv[]) { srand(time(NULL)); printf("%d\n", rand()); } Neither strace nor ltrace can detect the…
Sumit Ghosh
  • 1,033
  • 10
  • 29
1
vote
0 answers

Best way to replay all calls to a shared object?

I maintain a shared object written in c/c++. I would like to be able to log all calls to the library's methods in order to replay the same sequence of method calls for debug and testing. I can use ltrace to record all calls to the library but am…
cphurley82
  • 64
  • 7
1
vote
0 answers

ltrace : only show direct calls from a program to a library, and no inter-library call

When called with no argument other than the program to run, ltrace seems to display only the calls made by the program into shared libraries, and not the inter-library calls. I'd like to filter down these results by selecting the library the calls…
Romain Deterre
  • 546
  • 4
  • 16
1
vote
0 answers

ltrace exit with "is not an ELF file" for an executable that file finds "ELF 32-bit LSB shared object" on armv7

I am working on a armv7-a and try to use ltrace installed via buildroot. # ltrace /usr/bin/ssh-keygen -t ecdsa -b 256 "/usr/bin/ssh-keygen" is not an ELF file # file /usr/bin/ssh-keygen /usr/bin/ssh-keygen: ELF 32-bit LSB shared object, ARM, EABI5…
lalebarde
  • 1,684
  • 1
  • 21
  • 36
1
vote
1 answer

ltrace does not show sin() in the output

I wanted to list the functions used in my application program using ltrace. It works but does not list "sin()" in the output. #include #include int main() { float x=0; printf("Hello World!!\n"); x=sin(2); …
0
votes
1 answer

Could ltrace impact geteuid within a C program with sticky bits

I have a simple C program that does this int main(void) { printf("getuid: %d\n", getuid()); printf("geteuid: %d\n", geteuid(); return 0; } The owner of the executable of my program is the user "A", this executable have special…
0
votes
1 answer

Different instruction address shown in ltrace and objdump

I use ltrace and objdump to analyse the simple code below. But I find there is a difference on instruction address shown between ltrace and objdump. #include int main() { std::cout << "Hello"; return 0; } As the following info,…
wyb
  • 3
  • 3
0
votes
0 answers

How to use ltrace with a Go program

I'm trying to debug memory issue on Go, i.e. RSS keeps on increasing, no leak is found via pprof, most likely is due to Go not returning memory to OS when it's freed (classic scavenger issue in Go: https://github.com/golang/go/issues/30333) I'm…
Dian Bakti
  • 310
  • 5
  • 15
0
votes
1 answer

Unable to print to file from shared object

I have seen questions similar to this one on here before but I was unable to solve my problem from the answers to those. I have a file libfoo.c from which I'm creating a shared object. Using gcc's __attribute__((constructor)), I'd like to print a…
Peter
  • 2,919
  • 1
  • 16
  • 35
0
votes
1 answer

"/usr/bin/google-chrome" is not an ELF file

I am going to use ltrace for some applications like chrome but when I use it, I receive the following error message. "/usr/bin/google-chrome" is not an ELF file Does anybody know about the solution? I want to know what functions are exactly called…
M R
  • 31
  • 5
0
votes
0 answers

why doesn't ltrace show gets(), puts()

On Ubuntu Yakkety Yak: 4.8.0-59-generic, I can't get ltrace to work. I expect it to show me gets() and puts() but it doesn't. What am I doing wrong? // program name: e.c #include int main() { char str[80]; gets(str); …
GroovyDotCom
  • 1,304
  • 2
  • 15
  • 29
0
votes
1 answer

Debug with strace and ltrace

My program hung and I decided to ltrace and strace it. strace -p pid gives me an "infinite" printing on screen : lseek(3, 57114624, SEEK_SET) = 57114624 read(3, "\r\r\207\0\n\6O\0\16b\f\277\v\370\v1\ni\tm\10\245\7\335\7\25\6O\5v\5v"...,…
Kenenbek Arzymatov
  • 8,439
  • 19
  • 58
  • 109