我的进程已崩溃,我有一个核心转储。 我看到在运行类似的代码时进程崩溃了:
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*/}
};
我在核心转储中有一个完整的调用堆栈,但我不知道谁是运行“func”的继承者。有没有办法弄明白(可能是this
上的一些指针计算技巧?)
我没有实时附加进程,只有核心转储。
答案 0 :(得分:5)
您可以使用info vtbl this
或只打印*this
。您将在输出中看到继承者(在我的示例中为son1
):
(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)