How to identify the shared library, whose functions are currently being executed by an executable

288 Views Asked by At

An executable file, a.out, loads the shared libraries 1.so, 2.so and 3.so. There is a function func() implemented in each of the three libraries. When func() is invoked, I want to identify, which implementation of func() is executed.

I tried ltrace on the PID of the executable file. It only lists the func() call, but not the shared library.

Any suggestions?

1

There are 1 best solutions below

0
On

Using systemtap:

probe process("/path/to/1.so").function("func")
{
  printf("%d: 1.so\n", pid());
}       

probe process("/path/to/2.so").function("func")
{
  printf("%d: 2.so\n", pid());
}       

probe process("/path/to/3.so").function("func")
{
  printf("%d: 3.so\n", pid());
}       

Use it with:

sudo -E stap ./func.stap

With linux perf:

sudo perf probe -x /path/to/1.so func
sudo perf probe -x /path/to/2.so func
sudo perf probe -x /path/to/3.so func
sudo perf top -e probe_1:func,probe_2:func,probe3:func