1

In C#,I have an object say Shape which has two fields area and length.

I got a shapeList which is a collection of Shapes.

I have got a shapeList address in my crash dump.

I need a script in windbg that iterates through each item in the shapeList array and display the value of area alone for each shape.

Brian Rasmussen
  • 114,645
  • 34
  • 221
  • 317
Rockstart
  • 2,337
  • 5
  • 30
  • 59
  • 1
    have you looked at the windbg documentation that's included with the install? there are some very good instructions for scripting in the .chm file. – Chris Apr 25 '12 at 18:01

1 Answers1

3
    .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
Remi Lemarchand
  • 863
  • 6
  • 4
  • What is the difference between element size and length? How do i find the offset of the child object in parent? – Rockstart Apr 26 '12 at 06:21
  • Element size is the size of the element in the list, so if it's a reference type (like a class), it's 8 bytes (or 4 if 32bit). Length is the size of the array (i.e. _size on the list object). – Remi Lemarchand Apr 26 '12 at 11:39