Can I see somehow an VMT table in FREE Pascal?
In runtime you can get a pointer to VMT of an object instance with TypeOf intrinsic (like this: TypeOf(Obj)
). Internal structure of the returned VMT is documented in 8.2.12 Object types of the Free Pascal Programmer’s Guide.
You can also dump VMTs while compilation. To do that compile your program with -al
option ("List sourcecode lines in assembler file") and read lines in the generated .s
file related to the VMTs. For your example I got this on my PC (Win32 for i386
target):
.section .data.n_VMT_$P$PROGRAM_$$_OB1,"d"
.balign 4
.globl VMT_$P$PROGRAM_$$_OB1
VMT_$P$PROGRAM_$$_OB1:
.long 4,-4,0
.long P$PROGRAM$_$OB1_$__$$_F1$$LONGINT
.long P$PROGRAM$_$OB1_$__$$_F2$$LONGINT
.long 0
.section .data.n_VMT_$P$PROGRAM_$$_OB2,"d"
.balign 4
.globl VMT_$P$PROGRAM_$$_OB2
VMT_$P$PROGRAM_$$_OB2:
.long 4,-4
.long VMT_$P$PROGRAM_$$_OB1
.long P$PROGRAM$_$OB2_$__$$_F1$$LONGINT
.long P$PROGRAM$_$OB2_$__$$_F2$$LONGINT
.long P$PROGRAM$_$OB2_$__$$_F3$$LONGINT
.long 0
.section .data.n_VMT_$P$PROGRAM_$$_OB3,"d"
.balign 4
.globl VMT_$P$PROGRAM_$$_OB3
VMT_$P$PROGRAM_$$_OB3:
.long 4,-4
.long VMT_$P$PROGRAM_$$_OB2
.long P$PROGRAM$_$OB3_$__$$_F1$$LONGINT
.long P$PROGRAM$_$OB3_$__$$_F2$$LONGINT
.long P$PROGRAM$_$OB3_$__$$_F3$$LONGINT
.long 0
Here you can clearly see that virtual methods are started from fourth cells in the VMTs. First cell of an VMT is size of object, third is the pointer to parent's VMT. The -4
s are negative sizes of objects and used for validating pointers to VMT.
And will there be ONE table for all functions or more (table between [Ob1 AND Ob2] and table between [Ob2 AND Ob3] )?
One VMT for each object type. There is no tables between objects, VMTs are attached to objects itself.