简体   繁体   English

如何在帕斯卡中看到 VMT?

[英]How can I see VMT in pascal?

Can I see somehow an VMT table in FREE Pascal?我能以某种方式在 FREE Pascal 中看到 VMT 表吗? I am interested if VMT table has the same number of items in two objects that are connected by heredity?如果 VMT 表在通过遗传连接的两个对象中具有相同数量的项目,我很感兴趣?

For example in this model, what will be in the VMT table?例如,在这个 model 中,VMT 表中会有什么?

And will there be ONE table for all functions or more (table between [Ob1 AND Ob2] and table between [Ob2 AND Ob3] )?所有功能或更多功能是否会有一张表( [Ob1 AND Ob2] 之间的表格和 [Ob2 AND Ob3] 之间的表格)?

What will be in the table(s)?表格中会有什么?

Ob1 = object
  constructor Init;
  function f1..; virtual;
  function f2..; virtual;
end;


Ob2 = object(Ob1)
  constructor Init;
  function f1...; virtual;
  function f2...; virtual;
  function f3...; virtual;
end;

Ob3 = object(Ob2)
  constructor Init;
  function f1...; virtual;
  function f2...; virtual;
  function f3...; virtual;
end;

Can I see somehow an VMT table in FREE Pascal?我能以某种方式在 FREE Pascal 中看到 VMT 表吗?

In runtime you can get a pointer to VMT of an object instance with TypeOf intrinsic (like this: TypeOf(Obj) ).在运行时,您可以获得指向具有TypeOf内在属性的 object 实例的 VMT 的指针(例如: TypeOf(Obj) )。 Internal structure of the returned VMT is documented in 8.2.12 Object types of the Free Pascal Programmer's Guide.返回的 VMT 的内部结构记录在 Free Pascal Programmer's Guide 的8.2.12 Object 类型中。

You can also dump VMTs while compilation.您还可以在编译时转储 VMT。 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.为此,请使用-al选项( “列出汇编程序文件中的源代码行” )编译您的程序,并在生成的.s文件中读取与 VMT 相关的行。 For your example I got this on my PC ( Win32 for i386 target):对于你的例子,我在我的电脑上得到了这个( 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.在这里您可以清楚地看到虚拟方法是从 VMT 中的第四个单元格开始的。 First cell of an VMT is size of object, third is the pointer to parent's VMT. VMT 的第一个单元格大小为 object,第三个是指向父级 VMT 的指针。 The -4 s are negative sizes of objects and used for validating pointers to VMT. -4是对象的负大小,用于验证指向 VMT 的指针。

And will there be ONE table for all functions or more (table between [Ob1 AND Ob2] and table between [Ob2 AND Ob3] )?所有功能或更多功能是否会有一张表( [Ob1 AND Ob2] 之间的表格和 [Ob2 AND Ob3] 之间的表格)?

One VMT for each object type.每个 object 类型一个 VMT。 There is no tables between objects, VMTs are attached to objects itself.对象之间没有表,VMT 附加到对象本身。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM