6

I was able to generate the callgraph of one file using gnu - cflow, but I was not able to find out how to generate the call graph for multiple files using cflow.

I tried following

  • cflow test.c,hello.c

    It generates the callgraph for test.c and not creating it for hello.c

  • cflow test.c hello.c

    It generates the callgraph for hello.c and not creating it for test.c

I don't know how to pass multiple files to cflow.

Any idea about this?

hello.c

int
 who_am_i (void)
 {
     struct passwd *pw;
     char *user = NULL;

     pw = getpwuid (geteuid ());
     if (pw)
     user = pw->pw_name;
     else if ((user = getenv ("USER")) == NULL)
     {
         fprintf (stderr, "I don't know!\n");
         return 1;
     }
     printf ("%s\n", user);
     unused_function();
     return 0;
 }

 int
 main (int argc, char **argv)
 {
     if (argc > 1)
     {
         fprintf (stderr, "usage: whoami\n");
         return 1;
     }
     return who_am_i ();
 }
 void unused_function()
 {
     printf();
     error1();
     printf();
 }
 void error1()
 {
     error2();
 }
 void error2()
 {

 }

test.c

int tests()
{ return 0;}
dbush
  • 205,898
  • 23
  • 218
  • 273
gramcha
  • 692
  • 9
  • 16
  • can you post the contents of hello.c and test.c? – Andreas Grapentin Mar 07 '13 at 07:43
  • @AndreasGrapentin i added the code. I just don't know how to pass multiple file names to the cflow. – gramcha Mar 07 '13 at 08:44
  • 1
    your second invocation is correct. `tests()` does not show up in your callgraph, because it is never called. – Andreas Grapentin Mar 07 '13 at 08:57
  • thanx @AndreasGrapentin. yes you are correct. I called that function in hello.c and its working. I have another doubt change the main() function name into main1(). Now execute the cflow hello.c it shows graph for all the functions in that file. If this is expected behavior why not tests() is not coming. Because main1() also not called anywhere. – gramcha Mar 07 '13 at 09:10
  • I don't really know. maybe cflow acts differently if there is no `main` function? I can only guess :) – Andreas Grapentin Mar 07 '13 at 11:41

2 Answers2

2
  • cflow test.c hello.c

Actually above statement is correct and tests() does not show up in callgraph, because it is never called.

answer given by @AndreasGrapentin

gramcha
  • 692
  • 9
  • 16
  • 1
    Also, if you don't want graphs for all functions, you can use --main option to specify what function you're interested in. For example, for who_am_i: `cflow --main who_am_i hello.c ../libFolder/*.c` This is included in info folder of cflow, just type `info cflow.info` and go to page 2 – alexey Nov 19 '14 at 00:46
2

Another convenient command is:

cflow *.c

Note:
This command will ignore C source files in all sub-directories.

Reference:
GNU cflow manual: Chapter 6-Controlling Symbol Types

For cflow to be able to process such declarations, declare __P as a wrapper, for example:

cflow --symbol __P:wrapper *.c

cs_w_y
  • 41
  • 5