C++ Automatic crash reports

Started by
7 comments, last by Wavesonics 16 years, 1 month ago
So I was looking at some one's C# code, and C#, admittedly a much more structured language where every problem produces an exception before crashing the program, provides functionality for attaching a handler for C# to call when it encounters an unhanded exception *anywhere* in your program. So using that this handler, he had it dump to disk and send the file to an FTP server. Then the server emailed him of the new crash report. I mean that is just fantastic, you know about every crash every time. So I am of course curious if anyone has come up with any interesting way of doing this in C++. Obvious problems being, C++ doesn't produce exceptions for crash conditions that you didn't specify, and doesn't provide any sort of functionality for staying alive a little longer to do something like send a crash report. Still, anyone come up with anything? Maybe another process which monitors it or something? Might be too slow for games, but for other software it would be nice.
==============================
A Developers Blog | Dark Rock Studios - My Site
Advertisement
You can catch C++ exceptions, Windows exceptions, and handle Unix signals to similar effects I would imagine.
If your target platform is Windows, you could for example use SetUnhandledExceptionFilter.
I have used AddVectoredExceptionHandler for something similar in the past, which worked nicely.
I'm pretty partial to writing cross platform code, but maybe in this case thats not possible
==============================
A Developers Blog | Dark Rock Studios - My Site
Quote:Original post by Wavesonics
I'm pretty partial to writing cross platform code, but maybe in this case thats not possible

Not possible here, unfortunately. The history of C and C++ is such that crash handling is considered the exclusive domain of the OS.
Quote:Original post by Sneftel
Quote:Original post by Wavesonics
I'm pretty partial to writing cross platform code, but maybe in this case thats not possible

Not possible here, unfortunately. The history of C and C++ is such that crash handling is considered the exclusive domain of the OS.


Would wrapping your entire main function with a catch (...) clause do the trick? I am assuming not, since SEGFAULT and such are not C++ exceptions.

However, on *nix machines you get a core dump on a crash, so a monitor process could email that.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Not really. Any crash handler that exists inside the process that crashed is subject to some sort of destructive interference from the crash itself. For example a catch (...) block compiled with /EHa in MSVC will catch pretty much every SEH exception that the system can raise. However, it may not be in a position to do anything with that information. What if the SEH exception was due to a stack overflow? You'd want to generate a stack walk to display what function went bonkers, but in order to do that you need to perform the stack walk while the full contents of the stack are there, but that means you don't have the stack space necessary to call stack walking functions.
Would it work to write a crash handling class that attempts to implement crash handling for any operating system. Then you use #ifdef statements to let the complier select the operating system's functions to catch exceptions.

void CrashHandler::Initialize(){     #ifdef WINDOWS          // windows code     #endif     #ifdef LINUX          // linux code     #endif}


Not sure if you would actually be checking for 'WINDOWS' or 'LINUX' specifically but hopefully you get the idea.
My current game project Platform RPG
Well that would work, but like a lot of them are saying, the big problem here is that so many things that could crash the program would not produce exceptions in C++.
==============================
A Developers Blog | Dark Rock Studios - My Site

This topic is closed to new replies.

Advertisement