views:

140

answers:

5

Is there a flag I can set so that the compiler (linker?) will output a list of all the functions called by (not just defined in) each separate source file during the compilation(linking) process?

Thanks,

+3  A: 

I don't know if VS can do that, but you can use doxygen to generate a call graph for each function.

Dima
+1 Doxygen is a great tool.
luke
+2  A: 

You can try CppDepends to generate dependency map of your project along with some other useful information

Dror Helper
A: 

or you can use a different editor. For instance, SourceInsight does a great job producing call/calledby graphs real time in the editor.

For a programmatic output: I found oing C code unit testing on a shoestring very interesting. For Visual Studio it needs some manual work since Visual Studio has poor C99 compatibility.

External tools (like doxygen and CppDepends) are very useful, as long as you can live with 2 constrainst:

  • not only call dependencies, but also dependencies on i.e. global variables are tracked
  • dependencies are static

For the static dependencies, consider the following example:

void foo(boolean b)
{
   if (false == b)
   { bar1(); }
   else
   { bar2(); }
}

Static tools will then output both bar1 and bar2. A runtime call graph would show either bar1 or bar2 depending on the value of the parameter.

Adriaan
+1  A: 

Compile it into an object file and get the list of undefined external symbols in it. You can get the list automatically with the proper tools for your platform: in Linux it's readelf.

Pavel Shved
Interesting approach, but not very automated.
Bill
@Bill, how come it's not automated? Again, speaking of linux, you run the compiler (from your application building script) and then run a `readelf` program giving the object file as an input; it prints the info in subject with just a bit of post-processing. That's fairly automated. You can find the automated way on your platform, too. Just some platforms are not created for automation, so it's harder in them ;-)
Pavel Shved
This sounds more automated, yes. "study undefined external symbols" sounded pretty manual.
Bill
@Bill: thanks for pointing this out. By the way you're not the first one who notes my misuse of `study' term :-) Fixed post.
Pavel Shved
+1  A: 

For an individual function, right-click, and select Call-Browser->Show Call Graph.

If you do this from main() you get a call tree for the main() thread. You would have to do this on the entry point of each thread to get a complete view of a multi-threaded application. It may not handle functions invoked through pointers of course.

Clifford