我的进程崩溃了,并且我有一个核心转储。
我看到运行类似的代码时进程崩溃了:
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
的一些指针计算技巧?)我没有实时附加流程,只有核心转储。
最佳答案
您可以使用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)
关于c++ - 使用GDB调试核心转储时,知道谁是继承者,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46197009/