Convert std :: exception to EXCEPTION_POINTERS

Maybe I totally don’t understand how to use the Google Breakpad API, and I am open to comments / suggestions / rude remarks if that is the case. I am trying to call the following C ++ function:

bool WriteMinidumpForException(EXCEPTION_POINTERS* exinfo); 

I have a link to std::exception :

 try { return QApplication::notify(receiver, event); } catch (std::exception &ex) { eh_.WriteMinidumpForException(?????); // ... do some more stuff and ultimately kill this process } 

( eh_ is google_breakpad::ExceptionHandler .)

What do I put in ?????

Reference Information. The reason this is necessary (I think) is because Qt does not support the exception raised in the event handler. It will not propagate correctly, and thus the minidump that Breakpad creates is completely useless since the actual exception context has been lost. Instead, you should catch all exceptions and handle them in the QApplication::notify() override, which I am trying to do. In case of an exception, I want to immediately write my mini-package for this exception (which sounds like WriteMinidumpForException will do), and then notify the user and exit the application. But I'm not sure what to pass as parameter EXCEPTION_POINTERS* .

+4
source share
2 answers

In the MSVC compiler, C ++ exceptions are copied to the native environment to exclude Windows (SEH, Structured Exception Handling). There is a rather large impedance mismatch, although the concept of an exception filter does not have a good match in C ++. By the time the catch handler catches the exception, the SEH exception is already being processed and the stack is unwound. Information EXCEPTION_POINTERS - gonzo. Exception filters actually exist because they filter for a specific type that you want to catch, however they are automatically generated by the compiler. There is no reasonable C ++ syntax to make them useful.

You need to plunge into compiler support for handling SEH exceptions. Use the keywords __try, __except ( __finally optional), and your filter will catch the exception code for C ++ exception, 0xe04d5343 ("MSC"). However, you lose the ability to catch a certain type of C ++ exception that is in a CRT without a source. Put a C ++ try inside __try to fix this, so your __except only sees exceptions that C ++ code hasn't filtered.

Using SetUnhandledExceptionFilter () is another way to do this btw, you really should consider it valid as the ultimate support for any unhandled exception, regardless of code location. This is the best way to create a failed drive mini drive. And last but not least, creating a mini-drive of a failed application inside the process itself is not the best approach. There are many chances that this will not work; the state of the process can be badly damaged. One of the failure modes has a process lock. It is unlikely, given that heap damage is a very common cause of a crash. Correct this with a "defensive process", use a named event to signal it to create a mini-drive. Your exception filter should only set an event that always works.

+7
source

The exceptions of Windows SEH and C ++ are in no way intertwined - an easy way to solve this problem is to use your own __try __except wrap, for example. dereferencing a null pointer.

Sort of:

 __try { * (int *) 0 = 0; } __except ( eh_.WriteMinidumpForException(GetExceptionInformation()), EXCEPTION_EXECUTE_HANDLER ) { } 
+3
source

Source: https://habr.com/ru/post/1343824/


All Articles