My process has crashed, and I have a core dump. I see that the process crashed while running a code similar to that :
class father
{
public:
void virtual runVirtualFunc() = 0;
void func()
{
runVirtualFunc();
// ... crash here ... THIS IS THE PLACE I NEED TO KNOW WHO IS THE INHERITOR (so I could analyze which "runVirtualFunc" ran).
}
virtual ~father() {}
};
class son1 : public father
{
public:
void virtual runVirtualFunc() { /* do something 1*/}
};
class son2 : public father
{
public:
void virtual runVirtualFunc() { /* do something 2*/}
};
I have a full call stack in the core dump, but I don’t know who is the inheritor that runs the “func”. Is there a way to figure it out (maybe by some pointer calculation tricks on this ? )
I don’t have a live attached process, only core dump.
Advertisement
Answer
You can use info vtbl this or just print *this. You will see the inheritor in output (son1 in my example):
(gdb) info vtbl this
vtable for 'father' @ 0x400920 (subobject @ 0x613c20):
[0]: 0x4007d8 <son1::runVirtualFunc()>
(gdb) p *this
$2 = {_vptr.father = 0x400920 <vtable for son1+16>}
(gdb)