【问题标题】:Dumping array using Windbg使用 Windbg 转储数组
【发布时间】:2012-04-25 17:58:34
【问题描述】:

在 C# 中,我有一个对象 Shape,它有两个字段 arealength

我有一个 shapeList,它是 Shapes 的集合。

我的故障转储中有一个shapeList 地址。

我需要一个 windbg 中的脚本,它遍历 shapeList 数组中的每个项目,并为每个形状单独显示 area 的值。

【问题讨论】:

  • 您查看过安装中包含的windbg 文档吗? .chm 文件中有一些非常好的脚本说明。

标签: windbg crash-dumps sos


【解决方案1】:
    .for ( r $t1 = 0; @$t1 < [length] * [element size]; r $t1 = @$t1 + [element size];) {!do poi(poi(@$t1+poi([address of list]+0x8)+0x18)+[offset of child object in parent object) }

    For example:

     class Foo
        {
            public Bar MyBar { get; set; }
        }

        class Bar
        {
            public String MyString { get; set; }
        }

0:000> .for ( r $t1 = 0; @$t1 < 0x5 * 0x8; r $t1 = @$t1 + 0x8;) {!do poi(poi(@$t1+poi(0000000002362e40+0x8)+0x18)+0x8) }
Name:        testdebug.Bar
MethodTable: 000007fe95eb3928
EEClass:     000007fe95fc22d8
Size:        24(0x18) bytes
File:        C:\users\testdebug.exe
Fields:
              MT    Field   Offset                 Type VT     Attr            Value Name
000007fef47b4130  4000002        8        System.String  0 instance 00000000023653b0 <MyString>k__BackingField
Name:        testdebug.Bar
MethodTable: 000007fe95eb3928
EEClass:     000007fe95fc22d8
Size:        24(0x18) bytes
File:        C:\users\testdebug.exe
Fields:
              MT    Field   Offset                 Type VT     Attr            Value Name
000007fef47b4130  4000002        8        System.String  0 instance 0000000002365468 <MyString>k__BackingField
Name:        testdebug.Bar
MethodTable: 000007fe95eb3928
EEClass:     000007fe95fc22d8
Size:        24(0x18) bytes
File:        C:\users\testdebug.exe
Fields:
              MT    Field   Offset                 Type VT     Attr            Value Name
000007fef47b4130  4000002        8        System.String  0 instance 0000000002365520 <MyString>k__BackingField
Name:        testdebug.Bar
MethodTable: 000007fe95eb3928
EEClass:     000007fe95fc22d8
Size:        24(0x18) bytes
File:        C:\users\testdebug.exe
Fields:
              MT    Field   Offset                 Type VT     Attr            Value Name
000007fef47b4130  4000002        8        System.String  0 instance 00000000023655d8 <MyString>k__BackingField
Name:        testdebug.Bar
MethodTable: 000007fe95eb3928
EEClass:     000007fe95fc22d8
Size:        24(0x18) bytes
File:        C:\users\testdebug.exe
Fields:
              MT    Field   Offset                 Type VT     Attr            Value Name
000007fef47b4130  4000002        8        System.String  0 instance 0000000002365690 <MyString>k__BackingField

【讨论】:

  • 元素大小和长度有什么区别?如何在父对象中找到子对象的偏移量?
  • 元素大小是列表中元素的大小,因此如果是引用类型(如类),则为 8 个字节(如果 32 位则为 4 个)。长度是数组的大小(即列表对象上的_size)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多