3

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.

Karmastan
  • 5,618
  • 18
  • 24
prap19
  • 1,818
  • 3
  • 16
  • 26
  • possible duplicate of [Adding printf to the starting of all functions in a file](http://stackoverflow.com/questions/3078680/adding-printf-to-the-starting-of-all-functions-in-a-file) – Ignacio Vazquez-Abrams Nov 14 '10 at 03:33
  • but that will involve fiddling with kernel and it will be too much worm if i have to undo some of them or all of them. – prap19 Nov 14 '10 at 12:19

3 Answers3

5

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.

tcrosley
  • 779
  • 3
  • 13
  • these types of tools are typically for static analysis only, and would not work for functions called via a pointer – tcrosley Dec 05 '10 at 01:08
0

I believe Doxygen can do just that.

albert
  • 8,285
  • 3
  • 19
  • 32
Nathan Fellman
  • 122,701
  • 101
  • 260
  • 319
0

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.

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341