Capturing R6025 pure virtual call

久未见 提交于 2019-11-28 18:52:11

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.

1800 INFORMATION

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!