Somewhere deep inside an executable running on a Linux server, there is a C++ pure virtual function call. It causes the server to crash, leaving no program trace data, no stack trace and no core dump. Only some log files remain. It is almost certainly caused by a lifetime issue, and I have a good idea where it is happening, but I would like proof. I have tried to remedy this situation by using std::set_terminate
to set a handler to be run when terminate is called. This works in tests. For example, if I cause a pure virtual call, using:
class Base {
public:
Base() {}
virtual ~Base(){}
virtual void foo() = 0;
};
class Derived: public Base {
public:
Derived(): n_(0) {}
~Derived(){}
void foo() {
n_ = 1;
}
private:
int n_;
};
and then
Base* p = new Derived();
Base* p1 = p;
p->~Base();
p1->foo();
the handler works and produces trace data, stack trace and core dump. The runtime system prints
pure virtual method called
for this test.
There is no other call to set_terminate
in the code. The test is done when the server is up and running, so any subsequent calls that might have gazumped my handler should have happened, if they were going to. However, in the actual server, this does not catch the pure virtual call. The only situation I can think of that might cause this is a call to set the terminate handler after mine. Are there any other ways that my terminate handler could be avoided?