top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

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

+4 votes

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.

posted Jul 8, 2015 by Ankush Surelia

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
What it means after the graceful exit or at the time of crash you want to print the bt.
NOT crash.
Graceful / Normal exit

2 Answers

+2 votes

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.

answer Jul 8, 2015 by Chirag Gangdev
Yes a profiling tool like gprof would serve the purpose but it has its own pros & cons. It takes atleast 4 seconds to fetch the profiling data which wont serve my purpose.
Thanks anyways
+1 vote

If you just want to see list of functions hit during execution of binary then write each function name to a file (like log.txt) when it is called.

answer Jul 8, 2015 by Vimal Kumar Mishra
No Vimal. I don't want any change in the existing code base.
I am looking for any run-time options that can be passed with the binary and on normal exit that should provide me with a stack trace.
No way I dont think the process or its control keeps track of the functions visited.
Its possible with the help of a profiler (gProf). But It is time consuming so I was looking for a better alternative :)
If you are looking for profiling then try valgrind also if not happy with gprof.
I will look into that.
Similar Questions
+6 votes

Is there any way to kill the process which went to uninterruptible sleep (D) state due of some reason without rebooting machine??

I observed one of the process went to D-state during performance runs. Now, not able to kill the process using pkill or kill commands? Finally, we have to reboot the Linux machine.

Can anyone helps me out for this situation?? I don't want to reboot the machine.

We can kill the Zombie (Z) process but not able to kill process which is in D-state.

+1 vote

As far as i know when a process is created, 8MB of stack is allocated to it.
Is it right?

If not then is there any fix size or not?

If yes then please answer and Help To solve this question also.