Getting the call stack programatically
-
Greetings all. I've been wondering if there's some way to get an application's call stack programatically at run-time. What I have in mind is an error handler (particularly handy during develpment) that can find and list the call stack in the event of some major error happening. I use __FILE__ and __LINE__ quite a bit in debug versions of my code, but thought that just 'fetching' the call stack at the point of reporting an error may be a more elegant ways of doing things. Steve
-
Greetings all. I've been wondering if there's some way to get an application's call stack programatically at run-time. What I have in mind is an error handler (particularly handy during develpment) that can find and list the call stack in the event of some major error happening. I use __FILE__ and __LINE__ quite a bit in debug versions of my code, but thought that just 'fetching' the call stack at the point of reporting an error may be a more elegant ways of doing things. Steve
There are plenty of articles on doing this in MSDN magazine. Also if you search for 'under the hood' in msdev help you will find articles by JOhn Robbins, Matt Pietrek etc on doing this sort of thing. Setting exception handlers that then show you the call stack. Search for SuperASSERT written by John Robbins, which shows you the stack. MFC also provides a AfxDumpStack(). Win32 provides StackWalk(), there was a similar function in Win16.