To handle Vectored Exceptions with Crashpad, one does need to do the following:
- Integrate Crashpad
- Create a handler function with the following signature:
LONG WINAPI (PEXCEPTION_POINTERS) - Register the global exception handler, or use the handler in a
__try
/__except
block.
Useful Exception codes
0xC0000005
- Access Violation0xE06D7363
- External Exception0xC0000374
- Heap Corruption0xC000008E
- Float Divide By Zero0xC0000094
- Integer Divide By Zero0xC000001D
- Illegal Instruction
Integrating Crashpad
This step is described in this help article.
Creating the handler function
MSDN contains the documentation. An example function handling Access Violation errors (0xC0000005
).
LONG WINAPI VectoredExceptionHandler(PEXCEPTION_POINTERS pExceptionInfo)
{
// Access Violation
if (pExceptionInfo->ExceptionRecord->ExceptionCode == 0xC0000005) {
// CrashpadClient client;
// The client is already initialized, you can look at the
// integration article for an example
client.DumpAndCrash(pExceptionInfo);
return EXCEPTION_EXECUTE_HANDLER;
}
return EXCEPTION_CONTINUE_SEARCH;
}
Registering the handler function
This is done by the AddVectoredExceptionHandler function:
AddVectoredExceptionHandler(0, &::VectoredExceptionHandler);
Using the __try/__except block
Pass the handler function as an argument to __except
. Feed it PEXCEPTION_POINTERS
from GetExceptionInformation()
:
__try {
memset(nullptr, 42, 2000000);
}
__except (VectoredExceptionHandler(GetExceptionInformation()))
{
printf("all is good\n");
}
The result
If the necessary symbols have been uploaded, the uploaded minidump should contain the necessary information about the callstack, if at all possible. There are certain error scenarios, i.e. stack smashing, that render this impossible.
