I am looking for a tool like ltrace or strace that can trace locally defined functions in an executable. ltrace only traces dynamic library calls and strace only traces system calls. For example, given the following C program:
#include <stdio.h>
int triple ( int x )
{
return 3 * x;
}
int main (void)
{
printf("%d\n", triple(10));
return 0;
}
Running the program with ltrace
will show the call to printf
since that is a standard library function (which is a dynamic library on my system) and strace
will show all the system calls from the startup code, the system calls used to implement printf, and the shutdown code, but I want something that will show me that the function triple
was called. Assuming that the local functions have not been inlined by an optimizing compiler and that the binary has not been stripped (symbols removed), is there a tool that can do this?
Edit
A couple of clarifications:
- It is okay if the tool also provides trace information for non-local functions.
- I don't want to have to recompile the program(s) with support for specific tools, the symbol information in the executable should be enough.
- I would be really nice if I could use the tool to attach to existing processes like I can with ltrace/strace.