开发者

Can anyone suggest a way to trace every call of a function?

I want to trace each path of function calls. For eg:

int a()
{
    b();
    return 1;
}
void b()
{
}
int main()
{
    int x=a();
    return 0;
}

So my call trace is main->a->b In this manner I want to trace each set paths of calls. I have thought of a depth first search. But i am not sure how this would go. Can anyone 开发者_运维百科suggest me any concrete method to be implemented in perl? I will have C program file and will run a perl script over it to get call traces.


There are a number of free call-graph programs listed in this article, including egypt which is a small Perl script that uses gcc and Graphviz to generate the static call graph of a C program.


One way is automatically instrument the source code with probes that collect the information you want as the program runs. You can use a program transformation tool to do that.

Here's a paper on how do collect information abouth "which blocks" get executed, using a transformation system to insert such probes. A very small change to the specification of where to put probes, and some minor work to capture the current function would accomplish what you want in a relaible way.


I believe Doxygen can do just that.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜