9

If one were to visualize the running of a program, I suppose one would start by getting the call graphs of the program.

But how would you get the call graph of c/c++ programs while on the run?

edit: clarifications, I'm currently running things on linux, using g++, but I suppose I am also curious about solutions if I'm using a different platform.

kamziro
  • 7,882
  • 9
  • 55
  • 78
  • Try [Valgrind](http://valgrind.org/) or [Gprof](http://sourceware.org/binutils/docs-2.21/gprof/index.html) – ceving Aug 16 '11 at 11:49
  • +1 for helping Dr Kimble get his call graphs. – Kerrek SB Aug 16 '11 at 11:54
  • 1
    @kamziro: Why do you need *Runtime* call graphs? There are tools which can give you the callgraph by looking up from the code. – Alok Save Aug 16 '11 at 11:55
  • 1
    @Als: One possibility is that depending on the input, not all code paths are executed. You may be interested in the calls made for a particular input vector. – Oliver Charlesworth Aug 16 '11 at 12:00
  • @Oli Charlesworth: But an code analysis tool like Doxygen used with Graphviz will generate the graphs nicely, while it is rare that an runtime tool will be available as open source. – Alok Save Aug 16 '11 at 12:02
  • @Als: oprofile, [perf](https://perf.wiki.kernel.org/index.php/Tutorial), callgrind to name a few – sehe Aug 16 '11 at 12:29
  • @sehe: Yes, I had look that up myself & posted one as an answer. – Alok Save Aug 16 '11 at 12:30
  • Which system, and which compiler ? – philant Aug 16 '11 at 12:33
  • @Als: I want to visualize the actual program running, hence the runtime call graph. That is, I want to see the nodes making links to other nodes (function calls) happen in real time, or rather, slo-mo. – kamziro Aug 16 '11 at 13:14
  • @Als: Doxygen doesn't seem to be able to resolve call targets when there is any kind of overloading. I don't see how it can, considering it doesn't have a real C++ parser, and it doesn't really understand C++ lookup rules. – Ira Baxter Sep 08 '11 at 05:16

3 Answers3

6

I've used etrace to trace executions of programs.

Egypt does the same thing, but only has a limited support for C++.

Both requires the program to be instrumented with gcc.

philant
  • 34,748
  • 11
  • 69
  • 112
4

You can use KCachegrind to generate and analyze call graphs based on data generated by Valgrind's callgrind tool.

Alok Save
  • 202,538
  • 53
  • 430
  • 533
1

The Bug Validator from SofwareVerify (free public beta available) does this.

Excerpt from homepage:

C++ Bug Validator provides automatic execution history logging of applications as they run. There is no need to recompile or relink your application. C++ Bug Validator works with debug information and/or MAP files. C++ Bug Validator allows you to perform execution history logging on your entire application, or on just the DLLs you require.

(Markup from me).

I don't know how they do it, but obviously, it's possible.

eckes
  • 64,417
  • 29
  • 168
  • 201