Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

linux

ltrace

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?

like image 910
Sumit Ghosh Avatar asked Apr 23 '20 18:04

Sumit Ghosh


1 Answers

You can use uftrace utility written by Namhyung Kim. It's available as a package in Ubuntu although I built the code from master branch manually to make sure I use the newest vanilla version. Example main.c:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
  puts("Hello World");

  return EXIT_SUCCESS;
}

Build with -z now:

gcc -O2 main.c -z now -o main

ltrace doesn't work:

$ ltrace ./main
Hello World
+++ exited (status 0) +++

But uftrace does:

$ LD_LIBRARY_PATH=~/uftrace/libmcount ~/uftrace/uftrace -a --force ./main
Hello World
# DURATION     TID     FUNCTION
  58.231 us [ 16283] | puts("Hello World") = 12;

See this thread on project's site on Github: tracing library calls even if it has no PLT #592.

like image 127
Arkadiusz Drabczyk Avatar answered Oct 01 '22 13:10

Arkadiusz Drabczyk