vtbl layout

Bob McWhirter bob@werken.com
Sun Jan 31 23:58:00 GMT 1999


I've got a question, regarding the vtbls.

I'm working on some flavor of persistence layer library for
C++.

Somewhat like Colin, I need to know about and be able to frob
the vptrs on each object.  (actually, I'm laying out bytes in memory,
and blessing them into being by writing a valid vptr value into them.)

Anyhow, thus far, I've only been able to obtain the vptr of a class/object
by creating an exemplar object, and copying the vptr out of it.

Is there some way to find the address of the vtbl without just
inspecting the bytes of an object?

`nm` shows the Foo Virtual Table in my objects, but dlsym() does 
not seem to work (even if I pre-mangle the symbol name as shown by `nm`).

So, I was wondering if there is some way to directly get the address
of a given vtbl, or is my method of copying it out of an already
created object is the only way?

I'm using a slight derrivation of Coplien's vtbl munging from his
purple 'Idioms' book.  I'm not using this->_vptr, but rather setting
up base classes so that I know the vptr (whatever it might be called
by a particular compiler) is the first few bytes of an object.  Of couse
this isn't really guaranteed to work with multiple inheritence, etc.

Anyhow, if there is a way to get a ptr to a particular vtbl without
instatiating the object, that'd be lovely, as Right Now, I'm having
to basically throw away an object created solely for sucking out the vptr.

Thanks,

-Bob

(btw, I'm using just the 1.1.1 release on Solaris, which compile perfectly
 using SunPro 4.2 for bootstrapping.  Ged I hate SunPro compilers...)

--
Bob McWhirter    Shop Foreman, Decision Scientist, Cat Juggler 
Werken Digital   A division of the Benjamin J. Werken & Sons Company
bob@werken.com   http://www.werken.com./



More information about the Gcc mailing list