How to use ltrace

ltrace is an immensely useful tool to know what a program is doing. It displays the library calls made by a program that you execute. Just like strace, it will display the function called, list its input arguments and also display the return value from the function. Note that only calls made to dynamically linked libraries are reported. Not those to libraries that have been statically linked into the executable.

  • Installing ltrace is easy:
$ sudo apt install ltrace
  • Provide a program as argument when you invoke it:
$ ltrace ./foobar
$ ltrace touch

Note that it writes its output to stderr.

  • To redirect output of ltrace to a file:
$ ltrace -o foobar.log ./foobar
  • To filter and display only calls to a certain library function:
$ ltrace -e foobar_function_name ./foobar
$ ltrace -e malloc ./foobar

Note that you need to specify the exact name of the function. You can also use some method name and library name globs and regular expressions. For more info, please see the manual.

Tried with: ltrace 0.7.3

Advertisements

One thought on “How to use ltrace

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s