windows 捕获R6025纯虚呼叫

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/224163/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:30:20  来源:igfitidea点击:

Capturing R6025 pure virtual call

c++windowsminidumpdbghelp

提问by JProgrammer

I currently capture MiniDumps of unhandled exceptions using SetUnhandledExceptionFilterhowever at times I am getting "R6025: pure virtual function".

我目前使用SetUnhandledExceptionFilter但有时我会收到“R6025:纯虚函数”来捕获未处理异常的 MiniDumps 。

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.

我了解纯虚函数调用是如何发生的,我只是想知道是否可以捕获它们,以便我可以在那时创建 MiniDump。

回答by Brian R. Bondy

If you want to catch all crashes you have to do more than just: SetUnhandledExceptionFilter

如果您想捕获所有崩溃,您必须做的不仅仅是: SetUnhandledExceptionFilter

I would also set the abort handler, the purecall handler, unexpected, terminate, and invalid parameter handler.

我还将设置中止处理程序、purecall 处理程序、意外、终止和无效参数处理程序。

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

以上会将所有崩溃发送到您未处理的异常处理程序。

回答by 1800 INFORMATION

See this answer hereto 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:

为了帮助调试这些类型的问题,您可以在各种版本的 MSVC 中替换运行时库的 purecall 处理程序。您可以通过为您自己的函数提供此签名来做到这一点:

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.htmlfor more details.

(Note you can also call _set_purecall_handler()to install your handler in some versions of MSVC).

并在链接运行时库之前链接它。这使您可以控制检测到 purecall 时发生的情况。一旦你有了控制权,你就可以做一些比标准处理程序更有用的事情。我有一个处理程序,可以提供 purecall 发生位置的堆栈跟踪;请参见此处:http: //www.lenholgate.com/archives/000623.html了解更多详情。

(请注意,您还可以调用 _set_purecall_handler()在某些版本的 MSVC 中安装处理程序)。

So, in your purecall handler, make your minidump.

因此,在您的 purecall 处理程序中,制作您的小型转储。

回答by coppro

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

尝试定义有问题的纯虚拟。C++ 规则中没有任何内容禁止您定义纯虚拟,您可以出于多种原因使用它,其中最不重要的是在调用中获得回溯。唯一的问题是定义必须在声明之外(virtual void bla() = 0 { }无效)。