在使用GDB调试核心转储时知道谁是继承者

Oop*_*ser 5 c++ linux gdb

我的进程崩溃了,我有一个核心转储.我看到在运行类似的代码时进程崩溃了:

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*/} 
};
Run Code Online (Sandbox Code Playgroud)

我在核心转储中有一个完整的调用堆栈,但我不知道谁是运行"func"的继承者.有没有办法解决它(可能通过一些指针计算技巧this?)

我没有实时附加进程,只有核心转储.

ks1*_*322 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) 
Run Code Online (Sandbox Code Playgroud)