Know who the heir is when debugging core dumps using GDB

My process crashed and I have a kernel dump. I see that the process crashed when running code like this:

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 a kernel dump, but I don’t know who the heir that runs "func" is. Is there a way to figure this out (perhaps with some tricks of computing a pointer to this ?)

I do not have a real-time connected process, only the main dump.

+5
source share
1 answer

You can use info vtbl this or just print *this . You will see the son1 on the 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) 
+5
source

Source: https://habr.com/ru/post/1271757/


All Articles