Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List of all function calls made in an application

Tags:

How can we list all the functions being called in an application. I tried using GDB but its backtrace list only upto the main function call.

I need deeper list i.e list of all the functions being called by the main function and the function being called from these called functions and so on.

Is there a way to get this in gdb? Or could you give me suggestions on how to get this?

like image 379
broun Avatar asked Mar 03 '12 20:03

broun


1 Answers

How can we list all the functions being called in an application

For any realistically sized application, this list will have thousands of entries, which will probably make it useless.

You can find out all functions defined (but not necessarily called) in an application with the nm command, e.g.

nm /path/to/a.out | egrep ' [TW] ' 

You can also use GDB to set a breakpoint on each function:

(gdb) set logging on     # collect trace in gdb.txt (gdb) set confirm off    # you wouldn't want to confirm every one of them (gdb) rbreak .           # set a breakpoint on each function 

Once you continue, you'll hit a breakpoint for each function called. Use the disable and continue commands to move forward. I don't believe there is an easy way to automate that, unless you want to use Python scripting.

Already mentioned gprof is another good option.

like image 54
Employed Russian Avatar answered Dec 03 '22 01:12

Employed Russian