1

I have a (single-threaded) C++ program which involves a large number of nested function calls, lots of nested constructors, type conversions, etc. - and it's difficult to follow exactly what gets called when.

To compare two versions of the source, I would have liked to be able to look at a "trace" of all function invocatons - with or without the easily-printable arguments - by order of invocation time.

Obviously it is theoretically possible to obtain such a list, since, after all, it can be done manually using a debugger and repeated Step-Into's. Question is, can it be obtained relatively easily and without a lot of manual work?

Note:

  • I mean freestanding functions, members, and lambdas (which are basically members of anonymous classes).
  • If this is only possible for the parts of the program for which I have the source, and not for other libraries, that's good enough.
  • Assume the trace is not in the millions of calls; or - even better, don't...
einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • 1
    You can do this by instrumenting the binary. It is not hard to create a trampoline function which will trace entry and exit into the actual function. There is certainly software which already does it for you, but it's been a while since I check, so I am not sure what is current state of affairs. – SergeyA Jun 21 '21 at 17:58
  • See [this](https://stackoverflow.com/questions/3899870/print-call-stack-in-c-or-c) response. (And in particular [this](https://stackoverflow.com/a/26529030/980129).) – Manuel Jun 21 '21 at 18:02
  • @Manuel: I don't need the call stack, that's [double in C++](https://en.cppreference.com/w/cpp/header/stacktrace) (and via a standalone library before C++23). – einpoklum Jun 21 '21 at 18:21
  • 1
    There are some methods to trace all functions or some functions with debuggers or some advanced tracing tools (like System Tap or perf+uprobes). I did such traces with gdb (slow for programs with high number of functions) like in stackoverflow.com/questions/9549693 stackoverflow.com/questions/311840/ https://gist.github.com/Houdini/6a688fe06cc12b84fb61 – osgx Jul 03 '21 at 13:23

0 Answers0