All,
I saw an app, an SVN Visual Studio plugin, that displayed a beautiful readable stack trace, when it crashed.
I would love to add that to my application. How do I provide that? No emailing of the information, just a visual display is enough.
All,
I saw an app, an SVN Visual Studio plugin, that displayed a beautiful readable stack trace, when it crashed.
I would love to add that to my application. How do I provide that? No emailing of the information, just a visual display is enough.
I modified Jerry Coffin's code as you see below. Modifications:
A. I was always missing the most important frame of all: the line that actually triggered the exception. Turns out this was because the "do" loop was moving to the next frame at the top instead of at the bottom.
B. I removed the threading stuff.
C. I simplified a few bits.
You should cut the "WinMain()" function at the bottom and instead put the __try .. __except stuff in your own 'main/WinMain' function. Also replace 'YourMessage' with your own function to display a message box or email it or whatever.
The symbolic information is stored inside a .pdb file, not the .exe. You need to give your users your .pdb file, and you need to ensure that their process can find it. See the string inside the code below - replace this with a folder that will work on the users' machine, or NULL - NULL means it will search in the process's current working directory. The .pdb file must have the exact same name on the users' computer as it had when you ran your compiler - to configure this to something different, see "Properties > Linker > Debugging > Generate Program Database File".
OR use stackwalker from here...http://www.codeproject.com/Articles/11132/Walking-the-callstack
use file stackwalker.cpp and stackwalker.h in your project
Minimal code:
You need to generate some debugging info to see function names and line numbers Use proper flag in case of Microsoft VIsual C++ You may need to put .pdb file as well where your exe is.
The core of the necessary code is
StackWalk64
. To get much from that, you'll also want/need to get symbol names withSymGetSymFromAddr64
(which requiresSymLoadModule64
) and (probably)SymGetLineFromAddr64
andGetThreadContext
. If the target was written in C++, you'll probably also want to useUnDecorateSymbolName
. Along with those you'll need a few ancillaries likeSymInitialize
,SymCleanup
, and probablySymSetOptions
.Here's a fairly minimal demo. The stack dump it produces is more utilitarian than beautiful, but presumably with the basics of doing the stack trace, you can display the results as you see fit: