help needed on deciphering the g++ vtable dumps

Posted by Ganesh Kundapur on Stack Overflow See other posts from Stack Overflow or by Ganesh Kundapur
Published on 2011-01-07T22:42:32Z Indexed on 2011/01/07 22:54 UTC
Read the original article Hit count: 350

Filed under:

Hi, for the fallow class hierarchy class W { public: virtual void f() { cout << "W::f()" << endl; } virtual void g() { cout << "W::g()" << endl; } };

class AW : public virtual W { public: void g() { cout << "AW::g()" << endl; } };

class BW : public virtual W { public: void f() { cout << "BW::f()" << endl; } };

class CW : public AW, public BW { };

g++ -fdump-class-hierarchy is

Vtable for W
W::_ZTV1W: 4u entries
0 (int ()(...))0
4 (int (
)(...))(& _ZTI1W)
8 W::f 12 W::g

Class W
size=4 align=4
base size=4 base align=4
W (0xb6e3da50) 0 nearly-empty
vptr=((& W::_ZTV1W) + 8u)

Vtable for AW
AW::_ZTV2AW: 7u entries
0 0u
4 0u
8 0u
12 (int ()(...))0
16 (int (
)(...))(& _ZTI2AW)
20 W::f
24 AW::g

VTT for AW
AW::_ZTT2AW: 2u entries
0 ((& AW::_ZTV2AW) + 20u)
4 ((& AW::_ZTV2AW) + 20u)

Class AW
size=4 align=4
base size=4 base align=4
AW (0xb6dbf6c0) 0 nearly-empty
vptridx=0u vptr=((& AW::_ZTV2AW) + 20u)
W (0xb6e3da8c) 0 nearly-empty virtual
primary-for AW (0xb6dbf6c0)
vptridx=4u vbaseoffset=-0x00000000000000014

Vtable for BW
BW::_ZTV2BW: 7u entries
0 0u
4 0u
8 0u
12 (int ()(...))0
16 (int (
)(...))(& _ZTI2BW)
20 BW::f
24 W::g

VTT for BW
BW::_ZTT2BW: 2u entries
0 ((& BW::_ZTV2BW) + 20u)
4 ((& BW::_ZTV2BW) + 20u)

Class BW
size=4 align=4
base size=4 base align=4
BW (0xb6dbf7c0) 0 nearly-empty
vptridx=0u vptr=((& BW::_ZTV2BW) + 20u)
W (0xb6e3dac8) 0 nearly-empty virtual
primary-for BW (0xb6dbf7c0)
vptridx=4u vbaseoffset=-0x00000000000000014

Vtable for CW
CW::_ZTV2CW: 14u entries
0 0u
4 0u
8 4u
12 (int ()(...))0
16 (int (
)(...))(& _ZTI2CW)
20 BW::_ZTv0_n12_N2BW1fEv
24 AW::g
28 4294967292u
32 4294967292u
36 0u
40 (int ()(...))-0x00000000000000004
44 (int (
)(...))(& _ZTI2CW)
48 BW::f
52 0u

Construction vtable for AW (0xb6dbf8c0 instance) in CW
CW::_ZTC2CW0_2AW: 7u entries
0 0u
4 0u
8 0u
12 (int ()(...))0
16 (int (
)(...))(& _ZTI2AW)
20 W::f
24 AW::g

Construction vtable for BW (0xb6dbf900 instance) in CW
CW::_ZTC2CW4_2BW: 13u entries
0 4294967292u
4 4294967292u
8 0u
12 (int ()(...))0
16 (int (
)(...))(& _ZTI2BW)
20 BW::f
24 0u
28 0u
32 4u
36 (int ()(...))4
40 (int (
)(...))(& _ZTI2BW)
44 BW::_ZTv0_n12_N2BW1fEv
48 W::g

VTT for CW
CW::_ZTT2CW: 7u entries
0 ((& CW::_ZTV2CW) + 20u)
4 ((& CW::_ZTC2CW0_2AW) + 20u)
8 ((& CW::_ZTC2CW0_2AW) + 20u)
12 ((& CW::_ZTC2CW4_2BW) + 20u)
16 ((& CW::_ZTC2CW4_2BW) + 44u)
20 ((& CW::_ZTV2CW) + 20u)
24 ((& CW::_ZTV2CW) + 48u)

Class CW
size=8 align=4
base size=8 base align=4
CW (0xb6bea2d0) 0
vptridx=0u vptr=((& CW::_ZTV2CW) + 20u)
AW (0xb6dbf8c0) 0 nearly-empty
primary-for CW (0xb6bea2d0)
subvttidx=4u
W (0xb6e3db04) 0 nearly-empty virtual
primary-for AW (0xb6dbf8c0)
vptridx=20u vbaseoffset=-0x00000000000000014
BW (0xb6dbf900) 4 nearly-empty
lost-primary
subvttidx=12u vptridx=24u vptr=((& CW::_ZTV2CW) + 48u)
W (0xb6e3db04) alternative-path

what are each entries in
Vtable for AW
AW::_ZTV2AW: 7u entries
0 0u // ?
4 0u // ?
8 0u // ?

Vtable for CW
CW::_ZTV2CW: 14u entries
0 0u // ?
4 0u // ?
8 4u // ?
12 (int ()(...))0
16 (int (
)(...))(& _ZTI2CW)
20 BW::_ZTv0_n12_N2BW1fEv // ?
24 AW::g
28 4294967292u // ?
32 4294967292u // ?
36 0u // ?
40 (int ()(...))-0x00000000000000004 // some delta
44 (int (
)(...))(& _ZTI2CW)
48 BW::f
52 0u // ?

Thanks, Ganesh

© Stack Overflow or respective owner

Related posts about c++