Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capturing R6025 pure virtual call

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.

like image 542
JProgrammer Avatar asked Oct 22 '08 01:10

JProgrammer


People also ask

Can we call pure virtual function?

You may call a virtual function as long as it is not a pure virtual function, and as long as you know that what you are calling is the method from the class itself and not expecting any polymorphism. Calling a pure virtual function from a constructor is undefined behaviour even if it has an implementation.

What does pure virtual function call mean?

A pure virtual function is a function that must be overridden in a derived class and need not be defined. A virtual function is declared to be “pure” using the curious =0 syntax.

What is difference between pure virtual and virtual?

A virtual function is a member function of base class which can be redefined by derived class. A pure virtual function is a member function of base class whose only declaration is provided in base class and should be defined in derived class otherwise derived class also becomes abstract.


2 Answers

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.

like image 130
Brian R. Bondy Avatar answered Sep 29 '22 09:09

Brian R. Bondy


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.

like image 32
1800 INFORMATION Avatar answered Sep 29 '22 09:09

1800 INFORMATION