【问题标题】:How can I get type information at runtime from a DMP file in a Windbg extension?如何在运行时从 Windbg 扩展中的 DMP 文件获取类型信息?
【发布时间】:2011-02-05 00:23:26
【问题描述】:

这与my previous question 有关,涉及从 dmp 文件中提取对象。

正如我在上一个问题中提到的,我可以通过创建包装“远程”对象成功地将对象从 dmp 文件中提取出来。到目前为止,我已经实现了其中的几个,并且似乎运行良好。但是,我遇到了障碍。

在一种情况下,指针存储在一个类中,例如“SomeBaseClass”类型,但该对象实际上属于“SomeDerivedClass”类型,它派生自“SomeBaseClass”。例如,它会是这样的:

MyApplication!SomeObject
   +0x000 field1            : Ptr32 SomeBaseClass
   +0x004 field2            : Ptr32 SomeOtherClass
   +0x008 field3            : Ptr32 SomeOtherClass

我需要一些方法来找出“field1”的实际类型是什么。

更具体地说,使用示例地址:

MyApplication!SomeObject
   +0x000 field1            : 0cae2e24 SomeBaseClass
   +0x004 field2            : 0x262c8d3c SomeOtherClass
   +0x008 field3            : 0x262c8d3c SomeOtherClass

0:000> dt SomeBaseClass 0cae2e24 
MyApplication!SomeBaseClass
   +0x000 __VFN_table : 0x02de89e4 
   +0x038 basefield1         : (null) 
   +0x03c basefield2        : 3

0:000> dt SomeDerivedClass 0cae2e24 
MyApplication!SomeDerivedClass
   +0x000 __VFN_table : 0x02de89e4 
   +0x038 basefield1        : (null) 
   +0x03c basefield2        : 3
   +0x040 derivedfield1     : 357
   +0x044 derivedfield2     : timecode_t

当我在 WinDbg 中时,我可以这样做:

dt 0x02de89e4 

它会显示类型:

0:000> dt 0x02de89e4 
SomeDerivedClass::`vftable'
Symbol  not found.

但是我如何在扩展中获得它?我可以使用 SearchMemory() 来查找“SomeDerivedClass::`vftable”吗?如果您关注我的其他问题,我需要此类型信息,以便知道要创建哪种类型的包装器远程类。我认为它可能最终成为某种案例陈述,我必须将字符串与类型匹配?我对此表示同意,但我仍然不知道在哪里可以得到代表相关对象类型的字符串(即上面示例中的 SomeObject->field1)。

【问题讨论】:

    标签: c++ object types windbg memory-dump


    【解决方案1】:

    DOH!这比我想象的要简单得多。虚函数表只是其他符号,因此我可以将 GetSymbol() 与 field1 的 vftable 的地址一起使用。然后简单地设置一个包含我期望的几种类型的 case 语句,并为这种情况创建正确的语句。

    例如:

    char buffer[255];
    ULONG64 displacement;
    GetSymbol(0x02de89e4,buffer, &displacement);
    
    dprintf("0x%08lx = %s\n", 0x02de89e4, buffer);
    

    在 WinDbg 中,当我运行扩展时会输出:

    0x02de89e4 = MyApplication!SomeDerivedClass::`vftable'
    

    简单。只需要解析那个缓冲区,我就可以走了......

    【讨论】:

    • 好问题和答案!
    猜你喜欢
    • 1970-01-01
    • 2013-05-28
    • 1970-01-01
    • 2010-10-20
    • 1970-01-01
    • 2013-02-08
    • 2020-10-15
    • 2011-07-29
    • 2010-11-05
    相关资源
    最近更新 更多