Chirag Gangdev
Chirag Gangdev

Reputation: 137

Is there a way to dump the complete stack trace after normal execution of the binary?

I want the complete stack trace, mainly the list of functions traversed in a normal execution of a binary.

AFAIK, GDB provides the trace only when it hits a break point or in case of a crash.

Upvotes: 0

Views: 144

Answers (2)

Andrew Henle
Andrew Henle

Reputation: 1

If your OS provides dtrace, you can use the PID provider:

pid Provider

The pid provider allows for tracing of the entry and return of any function in a user process ...

Upvotes: 0

unwind
unwind

Reputation: 399803

That is called the call graph.

That would require either:

  • Instrumentation, i.e. adding code into each function to record when entering/leaving it
  • Profiling, i.e. sampling the program's state and recording which functions are detected
  • Emulation, i.e. running the program on a fake/virtual CPU and recording when jumps occur

Of the above, only the first one would provide 100% accuracy, and of course in general its very hard to do since you often use libraries and those wouldn't be instrumented even if you got your own code to be.

The reason this is hard is that the stack frame "history" isn't normally recorded; once the program has stopped running there is no current stack frame to inspect, unlike when breaking in a debugger.

See also this question.

Upvotes: 3

Related Questions