开发者

Trace all user defined function calls using gdb

I want to trace all the user defined functions that have been called (in ord开发者_开发问答er, and preferably with the input params). Is there a way to do this using gdb? OR is there a better free/opensource application out there to do this job? Please note that I want to print only the user defined function calls.

for example:

int abc(int a, char b) {
  return xyz(a+b);
}

int xyz(int theta) {
  return theta * theta;
}

I need the following output:

abc(a, b); xyz(theta);

My codebase is pretty huge and is compiled in various pieces and hence I want to avoid using a tool which needs me to compile my source code again with some options enabled.

PS: I found that there are ways where you can define functions in gdb and pass in function names as params to find out there call trace. But in my case the code base is pretty huge and I'm starting off with it, so I'm not even sure what all functions are called etc. It wouldn't be practical to list all the functions in here.

TIA,


You need to run some form of third-party tool against your binary, something like Quantify (IBM) or Callgrind, (or as @Paul R mentioned above gprof). They will generate a call tree, which will give you the information you need, google: "call tree C functions" for example, will reveal lots of goodies you can link against your code...

If you want to roll your own, you'd need to add one line to to the top of each of your functions which creates a stack allocated object and you can catch the ctor/dtor sequence to know when you've entered and exited the function and then maintain a "stack" of these to generate your own call tree... pretty easy to do (in single threaded, complex in multi-threaded)...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜