Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Track vptr to VTABLE during object construction through inheritance chain...

I have a certain inheritance chain, when i make an object of any class in this chain, i want to include code in the constructors so that i can TRACK the initialization of vptrs through the inheritance chain from the most base to the current class!! i dont have any clue how i can really access vptr inside the object?? anybody if have any idea about accessing vptr, the pointer which points to the VTABLE, the table of addresses of virtual functions of the class, please help me...!!! :WAVE:
[492 byte] By [premartha] at [2007-11-11 7:05:48]
# 1 Re: Track vptr to VTABLE during object construction through inheritance chain...
you can't track the vptr initiailzation directly because the relevant code is "injected" as assembly directives straight into the prolog of the constructor. If you are convesrant in assmbly, you can disassemble the code of a constructor call and see the relevant parts. Notice that many modern linkers nowadays use a special segment for constructors and destructors so if you know how to read the .exe format of your platform, you can locate this segment and see what's going on.
The vptr itself is located either at offset 0, i.e., it's the first data member of the object, occupying 4 bytes. This convention is used by most Windows compilers. On POSIX systems, the vptr is located at the end of the object, i.e., sizeof(obj) -sizeof(int). After initialization, this piece of data contains the address of the vtable.
Danny at 2007-11-11 21:02:43 >