I currently capture MiniDumps of unhandled exceptions using SetUnhandledExceptionFilter
however at times I am getting "R6025: pure virtual function".
I understand how a pure virtual function call happens I am just wondering if it is possible to capture them so I can create a MiniDump at that point.
If you want to catch all crashes you have to do more than just: SetUnhandledExceptionFilter
I would also set the abort handler, the purecall handler, unexpected, terminate, and invalid parameter handler.
#include <signal.h>
inline void signal_handler(int)
{
terminator();
}
inline void terminator()
{
int*z = 0; *z=13;
}
inline void __cdecl invalid_parameter_handler(const wchar_t *, const wchar_t *, const wchar_t *, unsigned int, uintptr_t)
{
terminator();
}
And in your main put this:
signal(SIGABRT, signal_handler);
_set_abort_behavior(0, _WRITE_ABORT_MSG|_CALL_REPORTFAULT);
set_terminate( &terminator );
set_unexpected( &terminator );
_set_purecall_handler( &terminator );
_set_invalid_parameter_handler( &invalid_parameter_handler );
The above will send all crashes to your unhandled exception handler.
See this answer here to the question where do “pure virtual function call” crashes come from?.
To help with debugging these kinds of problems you can, in various versions of MSVC, replace the runtime library's purecall handler. You do this by providing your own function with this signature:
int __cdecl _purecall(void)
and linking it before you link the runtime library. This gives YOU control of what happens when a purecall is detected. Once you have control you can do something more useful than the standard handler. I have a handler that can provide a stack trace of where the purecall happened; see here: http://www.lenholgate.com/archives/000623.html for more details.
(Note you can also call
_set_purecall_handler()
to install your handler in some versions of MSVC).
So, in your purecall handler, make your minidump.
Try defining the offending pure virtual. There is nothing in the C++ rules that prohibit you from defining a pure virtual, and you can use this for a number of reasons, the least of which is getting a backtrace on the call. The only caviat is the definition must be outside the declaration (virtual void bla() = 0 { }
is not valid).
来源:https://stackoverflow.com/questions/224163/capturing-r6025-pure-virtual-call