Possible Duplicate:
print call stack in C or C++
Often times when debugging code I need to figure out who is calling the function that I have placed a debug statement in. I know that __FUNCTION__
evaluates to the name of the current function, but is there something similar that will give me the name of the callee? Or maybe print out the call stack?
The information must be available. If I put in an assert or code that will segfault, I get a stack trace that shows the entire call stack. Where does the stack trace-printing code get that information?
If you are unable to produce a platform-agnostic solution, then something that will work on x86_64 Ubuntu 12.04 compiled with gcc
will do. Bonus points for providing solutions for other platforms as well.