通过Windbg查看DataTable的值
使用Windbg查看内存中DataTable的值时,其实方法和查看普通对象是一样的,唯一要注意的时,DataTable对象中值的存储方式有些特别,DataRow中的值是存存放在DataTable的columnCollection中的,思路如下:
1、使用!dumpheap -stat 查找到DataTable的引用
2、使用!do查找到columnCollection
3、查看columnCollection的items是一个OBJECT[],其中每个对象都是System.Data.DataColumn。
4、数据是存放在System.Data.DataColumn的storage中。
直接看代码和步骤吧。
测试代码如下:
1.查找到DataTable的引用
0:003> !dumpheap -stat
total 3,790 objects
Statistics:
MT Count TotalSize Class Name
0x7bec812c 1 12 System.Xml.XmlNonNormalizer
0x7bec7e9c 1 12 System.Xml.XmlDownloadManager
....................................................
0x002d6970 1 232 System.Data.DataTable
.......................................
2. 查看DataTable
0:003> !dumpheap -mt 0x002d6970
Address MT Size Gen
0x01e08a64 0x002d6970 232 1 System.Data.DataTable
total 1 objects
0:003> !dumpobj 0x01e08a64
Name: System.Data.DataTable
MethodTable 0x002d6970
EEClass 0x03df0bd0
Size 232(0xe8) bytes
GC Generation: 1
mdToken: 0x0200003d (c:\windows\assembly\gac\system.data\1.0.5000.0__b77a5c561934e089\system.data.dll)
FieldDesc*: 0x002d5ab8
MT Field Offset Type Attr Value Name
0x7b308b0c 0x4000583 0x4 CLASS instance 0x00000000 site
0x7b308b0c 0x4000584 0x8 CLASS instance 0x00000000 events
0x7b308b0c 0x4000582 0x44 CLASS static 0x01e08d50 EventDisposed
0x002d6970 0x40003ee 0xc CLASS instance 0x00000000 dataSet
0x002d6970 0x40003ef 0x10 CLASS instance 0x00000000 defaultView
0x002d6970 0x40003f0 0xa8 System.Int32 instance 101 nextRowID
0x002d6970 0x40003f1 0x14 CLASS instance 0x01e08e34 rowCollection
0x002d6970 0x40003f2 0x18 CLASS instance 0x01e09080 columnCollection
0x002d6970 0x40003f3 0x1c CLASS instance 0x01e08ec8 constraintCollection
0x002d6970 0x40003f4 0xac System.Int32 instance 2 elementColumnCount
0x002d6970 0x40003f5 0x20 CLASS instance 0x01e08f50 parentRelationsCollection
0x002d6970 0x40003f6 0x24 CLASS instance 0x01e08fe0 childRelationsCollection
0x002d6970 0x40003f7 0x28 CLASS instance 0x01e08d5c recordManager
0x002d6970 0x40003f8 0x2c CLASS instance 0x01e092b0 indexes
0x002d6970 0x40003f9 0x30 CLASS instance 0x00000000 shadowIndexes
0x002d6970 0x40003fa 0x34 CLASS instance 0x00000000 extendedProperties
0x002d6970 0x40003fb 0x38 CLASS instance 0x01dd1200 tableName
0x002d6970 0x40003fc 0x3c CLASS instance 0x00000000 tableNamespace
0x002d6970 0x40003fd 0x40 CLASS instance 0x01dd1200 tablePrefix
0x002d6970 0x40003fe 0xb4 System.Boolean instance 0 caseSensitive
0x002d6970 0x40003ff 0xb5 System.Boolean instance 1 caseSensitiveAmbient
0x002d6970 0x4000400 0x44 CLASS instance 0x00000000 culture
0x002d6970 0x4000401 0x48 CLASS instance 0x00000000 displayExpression
0x002d6970 0x4000402 0x4c CLASS instance 0x01dddac8 compareInfo
0x002d6970 0x4000403 0xb0 System.Int32 instance 25 compareFlags
0x002d6970 0x4000404 0xb6 System.Boolean instance 1 fNestedInDataset
0x002d6970 0x4000405 0x50 CLASS instance 0x00000000 encodedTableName
0x002d6970 0x4000406 0x54 CLASS instance 0x00000000 xmlText
0x002d6970 0x4000407 0x58 CLASS instance 0x00000000 _colUnique
0x002d6970 0x4000408 0xb7 System.Boolean instance 0 textOnly
0x002d6970 0x4000409 0xc4 VALUETYPE instance start at 01e08b28 minOccurs
0x002d6970 0x400040a 0xd4 VALUETYPE instance start at 01e08b38 maxOccurs
0x002d6970 0x400040b 0xb8 System.Boolean instance 0 repeatableElement
0x002d6970 0x400040c 0x5c CLASS instance 0x01e08b68 typeName
0x002d6970 0x400040f 0x60 CLASS instance 0x00000000 primaryKey
0x002d6970 0x4000410 0x64 CLASS instance 0x01e08b4c primaryIndex
0x002d6970 0x4000411 0x68 CLASS instance 0x00000000 delayedSetPrimaryKey
..................................
查看具体的columnCollection
0:003> !do 0x01e09080
Name: System.Data.DataColumnCollection
MethodTable 0x002d71dc
EEClass 0x03df0c98
Size 52(0x34) bytes
GC Generation: 1
mdToken: 0x0200001a (c:\windows\assembly\gac\system.data\1.0.5000.0__b77a5c561934e089\system.data.dll)
FieldDesc*: 0x002d6e18
MT Field Offset Type Attr Value Name
0x002d6da0 0x4000331 0x3c CLASS static 0x01e08de4 RefreshEventArgs
0x002d71dc 0x4000376 0x4 CLASS instance 0x01e08a64 table
0x002d71dc 0x4000377 0x8 CLASS instance 0x01e090b4 list
0x002d71dc 0x4000378 0x28 System.Int32 instance 1 defaultNameIndex
0x002d71dc 0x4000379 0xc CLASS instance 0x00000000 delayedAddRangeColumns
0x002d71dc 0x400037a 0x10 CLASS instance 0x01e09670 columnQueue
0x002d71dc 0x400037b 0x14 CLASS instance 0x01e0911c columnFromName
0x002d71dc 0x400037c 0x18 CLASS instance 0x01e091e0 hashCodeProvider
0x002d71dc 0x400037d 0x1c CLASS instance 0x00000000 onCollectionChangedDelegate
0x002d71dc 0x400037e 0x20 CLASS instance 0x00000000 onCollectionChangingDelegate
0x002d71dc 0x400037f 0x24 CLASS instance 0x00000000 onColumnPropertyChangedDelegate
0x002d71dc 0x4000380 0x2c System.Boolean instance 0 fInClear
查看list
0:003> !do 0x01e090b4
Name: System.Collections.ArrayList
MethodTable 0x79ba2f5c
EEClass 0x79ba3098
Size 24(0x18) bytes
GC Generation: 1
mdToken: 0x02000100 (c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll)
FieldDesc*: 0x79ba30fc
MT Field Offset Type Attr Value Name
0x79ba2f5c 0x4000362 0x4 CLASS instance 0x01e090cc _items
0x79ba2f5c 0x4000363 0xc System.Int32 instance 2 _size
0x79ba2f5c 0x4000364 0x10 System.Int32 instance 3 _version
0x79ba2f5c 0x4000365 0x8 CLASS instance 0x00000000 _syncRoot
我们知道
0:003> !do -v 0x01e090cc
Name: System.Object[]
MethodTable 0x003f209c
EEClass 0x003f2018
Size 80(0x50) bytes
GC Generation: 1
Array: Rank 1, Type CLASS
Element Type: System.Object
Content: 16 items
------ Will only dump out valid managed objects ----
Address MT Class Name
0x01e0932c 0x002d7bc8 System.Data.DataColumn
0x01e09518 0x002d7bc8 System.Data.DataColumn
----------
所有DataTable的数据都是存放在System.Data.DataColumn中,在System.Data.DataColumn中有一个数组,加上表中有100行数据的话,那么上面这个结合中的每个System.Data.DataColumn都有一个数组来存放这100行的当前列的数据。ok,让我们接到向下看。
以第一列数据为例
0:003> !do 0x01e0932c
Name: System.Data.DataColumn
MethodTable 0x002d7bc8
EEClass 0x03df0cfc
Size 128(0x80) bytes
GC Generation: 1
mdToken: 0x02000017 (c:\windows\assembly\gac\system.data\1.0.5000.0__b77a5c561934e089\system.data.dll)
FieldDesc*: 0x002d7304
MT Field Offset Type Attr Value Name
0x7b308b0c 0x4000583 0x4 CLASS instance 0x00000000 site
..............................................
0x002d7bc8 0x4000369 0x40 CLASS instance 0x00000000 extendedProperties
0x002d7bc8 0x400036a 0x44 CLASS instance 0x00000000 onPropertyChangingDelegate
0x002d7bc8 0x400036b 0x48 CLASS instance 0x01e11688 storage
0x002d7bc8 0x400036c 0x1c System.Int64 instance 0 autoIncrementCurrent
数据就存放在storage中。
0:003> !do 0x01e11688
Name: System.Data.Common.StringStorage
MethodTable 0x040562b4
EEClass 0x03dfc674
Size 24(0x18) bytes
GC Generation: 0
mdToken: 0x020000c6 (c:\windows\assembly\gac\system.data\1.0.5000.0__b77a5c561934e089\system.data.dll)
FieldDesc*: 0x04056198
MT Field Offset Type Attr Value Name
0x0405557c 0x4000665 0x4 CLASS instance 0x01dd43c4 type
0x0405557c 0x4000666 0x8 CLASS instance 0x01e08a64 table
0x0405557c 0x4000667 0xc CLASS instance 0x00000000 dbNullBits
0x040562b4 0x4000761 0x10 CLASS instance 0x01e116c8 values
0x040562b4 0x4000760 0x4c CLASS static 0x01e116a0 DBNullObject
使用!do -v 查看数组对象
0:003> !do -v 0x01e116c8
Name: System.Object[]
MethodTable 0x003f209c
EEClass 0x003f2018
Size 528(0x210) bytes
GC Generation: 0
Array: Rank 1, Type CLASS
Element Type: System.Object
Content: 128 items
------ Will only dump out valid managed objects ----
Address MT Class Name
0x01e11da4 0x79b946b0 System.String
0x01e11f18 0x79b946b0 System.String
0x01e11ff4 0x79b946b0 System.String
0x01e120d0 0x79b946b0 System.String
0x01e121ac 0x79b946b0 System.String
0x01e12288 0x79b946b0 System.String
0x01e12364 0x79b946b0 System.String
0x01e12440 0x79b946b0 System.String
0x01e1251c 0x79b946b0 System.String
0x01e125f8 0x79b946b0 System.String
0x01e126d8 0x79b946b0 System.String
0x01e127bc 0x79b946b0 System.String
...........................
顺便找个数据来看看呢
0:003> !do 0x01e11da4
String: Test0
终于找到了他了吧。
1、使用!dumpheap -stat 查找到DataTable的引用
2、使用!do查找到columnCollection
3、查看columnCollection的items是一个OBJECT[],其中每个对象都是System.Data.DataColumn。
4、数据是存放在System.Data.DataColumn的storage中。
直接看代码和步骤吧。
测试代码如下:
Code
1.查找到DataTable的引用
0:003> !dumpheap -stat
total 3,790 objects
Statistics:
MT Count TotalSize Class Name
0x7bec812c 1 12 System.Xml.XmlNonNormalizer
0x7bec7e9c 1 12 System.Xml.XmlDownloadManager
....................................................
0x002d6970 1 232 System.Data.DataTable
.......................................
2. 查看DataTable
0:003> !dumpheap -mt 0x002d6970
Address MT Size Gen
0x01e08a64 0x002d6970 232 1 System.Data.DataTable
total 1 objects
0:003> !dumpobj 0x01e08a64
Name: System.Data.DataTable
MethodTable 0x002d6970
EEClass 0x03df0bd0
Size 232(0xe8) bytes
GC Generation: 1
mdToken: 0x0200003d (c:\windows\assembly\gac\system.data\1.0.5000.0__b77a5c561934e089\system.data.dll)
FieldDesc*: 0x002d5ab8
MT Field Offset Type Attr Value Name
0x7b308b0c 0x4000583 0x4 CLASS instance 0x00000000 site
0x7b308b0c 0x4000584 0x8 CLASS instance 0x00000000 events
0x7b308b0c 0x4000582 0x44 CLASS static 0x01e08d50 EventDisposed
0x002d6970 0x40003ee 0xc CLASS instance 0x00000000 dataSet
0x002d6970 0x40003ef 0x10 CLASS instance 0x00000000 defaultView
0x002d6970 0x40003f0 0xa8 System.Int32 instance 101 nextRowID
0x002d6970 0x40003f1 0x14 CLASS instance 0x01e08e34 rowCollection
0x002d6970 0x40003f2 0x18 CLASS instance 0x01e09080 columnCollection
0x002d6970 0x40003f3 0x1c CLASS instance 0x01e08ec8 constraintCollection
0x002d6970 0x40003f4 0xac System.Int32 instance 2 elementColumnCount
0x002d6970 0x40003f5 0x20 CLASS instance 0x01e08f50 parentRelationsCollection
0x002d6970 0x40003f6 0x24 CLASS instance 0x01e08fe0 childRelationsCollection
0x002d6970 0x40003f7 0x28 CLASS instance 0x01e08d5c recordManager
0x002d6970 0x40003f8 0x2c CLASS instance 0x01e092b0 indexes
0x002d6970 0x40003f9 0x30 CLASS instance 0x00000000 shadowIndexes
0x002d6970 0x40003fa 0x34 CLASS instance 0x00000000 extendedProperties
0x002d6970 0x40003fb 0x38 CLASS instance 0x01dd1200 tableName
0x002d6970 0x40003fc 0x3c CLASS instance 0x00000000 tableNamespace
0x002d6970 0x40003fd 0x40 CLASS instance 0x01dd1200 tablePrefix
0x002d6970 0x40003fe 0xb4 System.Boolean instance 0 caseSensitive
0x002d6970 0x40003ff 0xb5 System.Boolean instance 1 caseSensitiveAmbient
0x002d6970 0x4000400 0x44 CLASS instance 0x00000000 culture
0x002d6970 0x4000401 0x48 CLASS instance 0x00000000 displayExpression
0x002d6970 0x4000402 0x4c CLASS instance 0x01dddac8 compareInfo
0x002d6970 0x4000403 0xb0 System.Int32 instance 25 compareFlags
0x002d6970 0x4000404 0xb6 System.Boolean instance 1 fNestedInDataset
0x002d6970 0x4000405 0x50 CLASS instance 0x00000000 encodedTableName
0x002d6970 0x4000406 0x54 CLASS instance 0x00000000 xmlText
0x002d6970 0x4000407 0x58 CLASS instance 0x00000000 _colUnique
0x002d6970 0x4000408 0xb7 System.Boolean instance 0 textOnly
0x002d6970 0x4000409 0xc4 VALUETYPE instance start at 01e08b28 minOccurs
0x002d6970 0x400040a 0xd4 VALUETYPE instance start at 01e08b38 maxOccurs
0x002d6970 0x400040b 0xb8 System.Boolean instance 0 repeatableElement
0x002d6970 0x400040c 0x5c CLASS instance 0x01e08b68 typeName
0x002d6970 0x400040f 0x60 CLASS instance 0x00000000 primaryKey
0x002d6970 0x4000410 0x64 CLASS instance 0x01e08b4c primaryIndex
0x002d6970 0x4000411 0x68 CLASS instance 0x00000000 delayedSetPrimaryKey
..................................
查看具体的columnCollection
0:003> !do 0x01e09080
Name: System.Data.DataColumnCollection
MethodTable 0x002d71dc
EEClass 0x03df0c98
Size 52(0x34) bytes
GC Generation: 1
mdToken: 0x0200001a (c:\windows\assembly\gac\system.data\1.0.5000.0__b77a5c561934e089\system.data.dll)
FieldDesc*: 0x002d6e18
MT Field Offset Type Attr Value Name
0x002d6da0 0x4000331 0x3c CLASS static 0x01e08de4 RefreshEventArgs
0x002d71dc 0x4000376 0x4 CLASS instance 0x01e08a64 table
0x002d71dc 0x4000377 0x8 CLASS instance 0x01e090b4 list
0x002d71dc 0x4000378 0x28 System.Int32 instance 1 defaultNameIndex
0x002d71dc 0x4000379 0xc CLASS instance 0x00000000 delayedAddRangeColumns
0x002d71dc 0x400037a 0x10 CLASS instance 0x01e09670 columnQueue
0x002d71dc 0x400037b 0x14 CLASS instance 0x01e0911c columnFromName
0x002d71dc 0x400037c 0x18 CLASS instance 0x01e091e0 hashCodeProvider
0x002d71dc 0x400037d 0x1c CLASS instance 0x00000000 onCollectionChangedDelegate
0x002d71dc 0x400037e 0x20 CLASS instance 0x00000000 onCollectionChangingDelegate
0x002d71dc 0x400037f 0x24 CLASS instance 0x00000000 onColumnPropertyChangedDelegate
0x002d71dc 0x4000380 0x2c System.Boolean instance 0 fInClear
查看list
0:003> !do 0x01e090b4
Name: System.Collections.ArrayList
MethodTable 0x79ba2f5c
EEClass 0x79ba3098
Size 24(0x18) bytes
GC Generation: 1
mdToken: 0x02000100 (c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll)
FieldDesc*: 0x79ba30fc
MT Field Offset Type Attr Value Name
0x79ba2f5c 0x4000362 0x4 CLASS instance 0x01e090cc _items
0x79ba2f5c 0x4000363 0xc System.Int32 instance 2 _size
0x79ba2f5c 0x4000364 0x10 System.Int32 instance 3 _version
0x79ba2f5c 0x4000365 0x8 CLASS instance 0x00000000 _syncRoot
我们知道
0:003> !do -v 0x01e090cc
Name: System.Object[]
MethodTable 0x003f209c
EEClass 0x003f2018
Size 80(0x50) bytes
GC Generation: 1
Array: Rank 1, Type CLASS
Element Type: System.Object
Content: 16 items
------ Will only dump out valid managed objects ----
Address MT Class Name
0x01e0932c 0x002d7bc8 System.Data.DataColumn
0x01e09518 0x002d7bc8 System.Data.DataColumn
----------
所有DataTable的数据都是存放在System.Data.DataColumn中,在System.Data.DataColumn中有一个数组,加上表中有100行数据的话,那么上面这个结合中的每个System.Data.DataColumn都有一个数组来存放这100行的当前列的数据。ok,让我们接到向下看。
以第一列数据为例
0:003> !do 0x01e0932c
Name: System.Data.DataColumn
MethodTable 0x002d7bc8
EEClass 0x03df0cfc
Size 128(0x80) bytes
GC Generation: 1
mdToken: 0x02000017 (c:\windows\assembly\gac\system.data\1.0.5000.0__b77a5c561934e089\system.data.dll)
FieldDesc*: 0x002d7304
MT Field Offset Type Attr Value Name
0x7b308b0c 0x4000583 0x4 CLASS instance 0x00000000 site
..............................................
0x002d7bc8 0x4000369 0x40 CLASS instance 0x00000000 extendedProperties
0x002d7bc8 0x400036a 0x44 CLASS instance 0x00000000 onPropertyChangingDelegate
0x002d7bc8 0x400036b 0x48 CLASS instance 0x01e11688 storage
0x002d7bc8 0x400036c 0x1c System.Int64 instance 0 autoIncrementCurrent
数据就存放在storage中。
0:003> !do 0x01e11688
Name: System.Data.Common.StringStorage
MethodTable 0x040562b4
EEClass 0x03dfc674
Size 24(0x18) bytes
GC Generation: 0
mdToken: 0x020000c6 (c:\windows\assembly\gac\system.data\1.0.5000.0__b77a5c561934e089\system.data.dll)
FieldDesc*: 0x04056198
MT Field Offset Type Attr Value Name
0x0405557c 0x4000665 0x4 CLASS instance 0x01dd43c4 type
0x0405557c 0x4000666 0x8 CLASS instance 0x01e08a64 table
0x0405557c 0x4000667 0xc CLASS instance 0x00000000 dbNullBits
0x040562b4 0x4000761 0x10 CLASS instance 0x01e116c8 values
0x040562b4 0x4000760 0x4c CLASS static 0x01e116a0 DBNullObject
使用!do -v 查看数组对象
0:003> !do -v 0x01e116c8
Name: System.Object[]
MethodTable 0x003f209c
EEClass 0x003f2018
Size 528(0x210) bytes
GC Generation: 0
Array: Rank 1, Type CLASS
Element Type: System.Object
Content: 128 items
------ Will only dump out valid managed objects ----
Address MT Class Name
0x01e11da4 0x79b946b0 System.String
0x01e11f18 0x79b946b0 System.String
0x01e11ff4 0x79b946b0 System.String
0x01e120d0 0x79b946b0 System.String
0x01e121ac 0x79b946b0 System.String
0x01e12288 0x79b946b0 System.String
0x01e12364 0x79b946b0 System.String
0x01e12440 0x79b946b0 System.String
0x01e1251c 0x79b946b0 System.String
0x01e125f8 0x79b946b0 System.String
0x01e126d8 0x79b946b0 System.String
0x01e127bc 0x79b946b0 System.String
...........................
顺便找个数据来看看呢
0:003> !do 0x01e11da4
String: Test0
终于找到了他了吧。