Jump to content
  • Advertisement
Sign in to follow this  
Wavesonics

C++ Automatic crash reports

This topic is 3791 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
You can catch C++ exceptions, Windows exceptions, and handle Unix signals to similar effects I would imagine.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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++.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!