当前位置:Gxlcms > 数据库问题 > Windbg调试WPF的依赖属性

Windbg调试WPF的依赖属性

时间:2021-07-01 10:21:17 帮助过:38人阅读


比如:我们查看DataGridColumnHeader的Content依赖属性 
 1.我们用到的windbg的命令有:!do, !da -details, .formats 2.利用!do查看依赖对象的成员变量, 找到具体依赖属性的地址0:000> !do 00000000039a71d8Name:        System.Windows.Controls.Primitives.DataGridColumnHeaderMethodTable: 000007fee7e58090EEClass:     000007fee7885bd8Size:        384(0x180) bytesFile:        C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.dllFields:              MT    Field   Offset                 Type VT     Attr            Value Name000007fef3f2eb00  4000db0        8 ...eading.Dispatcher  0 instance 0000000002dd4e68 _dispatcher000007fef3f3bb88  4001321       10 ...endencyObjectType  0 instance 000000000308a530 _dType000007fef7825ac8  4001322       18        System.Object  0 instance 0000000000000000 _contextStorage000007fef3f3e898  4001323       20 ...ctiveValueEntry[]  0 instance 00000000042efb08 _effectiveValues000007fef7847b70  4001324       28        System.UInt32  1 instance          3680277 _packedData000007fef3f33708  400131f      7c0 ...ependencyProperty  0   static 0000000002dd5ef0 DirectDependencyProperty---------------------省略部分----000007fef3f33708  40002ca      950 ...ependencyProperty  0   static 0000000002dfd820 ContentProperty0000000000000000  40002cb      958                       0   static 0000000002dfd908 HasContentPropertyKey000007fef3f33708  40002cc      960 ...ependencyProperty  0   static 0000000002dfd948 HasContentProperty000007fef3f33708  40002cd      968 ...ependencyProperty  0   static 0000000002dfdb00 ContentTemplateProperty000007fef3f33708  40002ce      970 ...ependencyProperty  0   static 0000000002dfdc80 ContentTemplateSelectorProperty
3.利用!do命令查看依赖属性的成员变量值, 比如:0:000> !do 0000000002dfd820Name:        System.Windows.DependencyPropertyMethodTable: 000007fef3f33708EEClass:     000007fef3dd7550Size:        88(0x58) bytesFile:        C:\Windows\Microsoft.Net\assembly\GAC_MSIL\WindowsBase\v4.0_4.0.0.0__31bf3856ad364e35\WindowsBase.dllFields:              MT    Field   Offset                 Type VT     Attr            Value Name000007fef7826970  400133c        8        System.String  0 instance 0000000002dfd630 _name000007fef78282f8  400133d       10          System.Type  0 instance 0000000002d444b0 _propertyType000007fef78282f8  400133e       18          System.Type  0 instance 0000000002dfab80 _ownerType000007fef3f312a8  400133f       20 ....PropertyMetadata  0 instance 0000000002dfd7c0 _defaultMetadata000007fef3f31088  4001340       28 ...dateValueCallback  0 instance 0000000000000000 _validateValueCallback000007fef3f3e750  4001341       30 ...ndencyPropertyKey  0 instance 0000000000000000 _readOnlyKey000007fef4194818  4001342       40         System.Int32  1 instance          4194530 _packedData000007fef3f3e408  4001343       48 ....InsertionSortMap  1 instance 0000000002dfd868 _metadataMap000007fef3f30fc8  4001344       38 ...erceValueCallback  0 instance 0000000000000000 _designerCoerceValueCallback000007fef7825ac8  400133b      808        System.Object  0   static 0000000002d72000 UnsetValue000007fef3f3c6c0  4001345      800 ...ty, WindowsBase]]  1   static 0000000012d5bb10 RegisteredPropertyList000007fef7831c38  4001346      810 ...ections.Hashtable  0   static 0000000002d6f3d8 PropertyFromName000007fef782c858  4001347      5c8         System.Int32  1   static              868 GlobalIndexCount000007fef7825ac8  4001348      818        System.Object  0   static 0000000002d6f430 Synchronized000007fef78282f8  4001349      820          System.Type  0   static 0000000002d68808 NullableType
4.利用.formats 得到依赖属性, 分2步  1)利用.formats 0n得到_packedData十六进制  2)   去掉高位,Decimal描述的就是依赖属性在依赖对象中的存储索引
  如下:0:000> .formats 0n4194530Evaluate expression:  Hex:     00000000`004000e2  Decimal: 4194530  Octal:   0000000000000020000342  Binary:  00000000 00000000 00000000 00000000 00000000 01000000 00000000 11100010  Chars:   .....@..  Time:    Wed Feb 18 21:08:50 1970  Float:   low 5.87779e-039 high 0  Double:  2.07237e-3170:000> .formats 00e2Evaluate expression:  Hex:     00000000`000000e2  Decimal: 226  Octal:   0000000000000000000342  Binary:  00000000 00000000 00000000 00000000 00000000 00000000 00000000 11100010  Chars:   ........  Time:    Thu Jan 01 08:03:46 1970  Float:   low 3.16693e-043 high 0  Double:  1.11659e-321
可知ContentProperty依赖属性在DataGridColumnHeader中的索引为226
5. 根据第4步的index,从第2步依赖对象的_effectiveValues 得到依赖属性的具体值,分3步:  1)利用!da -details 查看_effectiveValues 数组所有元素的值  2)查看每个元素,根据_propertyIndex (即第4步得到的Decimal值)确定依赖属性  3)利用!do命令查看元素的_value成员的值
 比如:
0:000> !da -details 00000000042efb08Name:        System.Windows.EffectiveValueEntry[]MethodTable: 000007fef3f3e898EEClass:     000007fef3e0c8a0Size:        408(0x198) bytesArray:       Rank 1, Number of elements 24, Type VALUETYPEElement Methodtable: 000007fef3f36120[0] 00000000042efb18    Name:        System.Windows.EffectiveValueEntry    MethodTable: 000007fef3f36120    EEClass:     000007fef3dd8c90    Size:        32(0x20) bytes    File:        C:\Windows\Microsoft.Net\assembly\GAC_MSIL\WindowsBase\v4.0_4.0.0.0__31bf3856ad364e35\WindowsBase.dll    Fields:                      MT    Field   Offset                 Type VT     Attr            Value Name        000007fef7825ac8  400136e        0            System.Object      0     instance     0000000002e1c5d8     _value        000007fef7830940  400136f        8             System.Int16      1     instance                    3     _propertyIndex        000007fef41949d0  4001370        a             System.Int16      1     instance                    2     _source
--------------------------------省略部分------------------------------
[15] 00000000042efc08    Name:        System.Windows.EffectiveValueEntry    MethodTable: 000007fef3f36120    EEClass:     000007fef3dd8c90    Size:        32(0x20) bytes    File:        C:\Windows\Microsoft.Net\assembly\GAC_MSIL\WindowsBase\v4.0_4.0.0.0__31bf3856ad364e35\WindowsBase.dll    Fields:                      MT    Field   Offset                 Type VT     Attr            Value Name        000007fef7825ac8  400136e        0            System.Object      0     instance     00000000042efca0     _value        000007fef7830940  400136f        8             System.Int16      1     instance                  226     _propertyIndex        000007fef41949d0  4001370        a             System.Int16      1     instance                   65     _source

 可知ContentProperty为_effectiveValues的第16个元素, 其值存储在_value中
  0:000> !do 00000000042efca0    Name:        System.Windows.ModifiedValueMethodTable: 000007fef3f40d58EEClass:     000007fef3e0d000Size:        48(0x30) bytesFile:        C:\Windows\Microsoft.Net\assembly\GAC_MSIL\WindowsBase\v4.0_4.0.0.0__31bf3856ad364e35\WindowsBase.dllFields:              MT    Field   Offset                 Type VT     Attr            Value Name000007fef7825ac8  4001387        8        System.Object  0 instance 0000000000000000 _baseValue000007fef7825ac8  4001388       10        System.Object  0 instance 0000000000000000 _expressionValue000007fef7825ac8  4001389       18        System.Object  0 instance 0000000000000000 _animatedValue000007fef7825ac8  400138a       20        System.Object  0 instance 0000000002d93618 _coercedValue
6.根据第5步中的成员_coercedValue得到依赖属性的具体值,大功告成!
0:000> !do 0000000002d93618Name:        System.StringMethodTable: 000007fef7826970EEClass:     000007fef73aeec8Size:        36(0x24) bytesFile:        C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dllString:      导入数据源Fields:              MT    Field   Offset                 Type VT     Attr            Value Name000007fef782c858  40000ed        8         System.Int32  1 instance                5 m_stringLength000007fef782b398  40000ee        c          System.Char  1 instance             5bfc m_firstChar000007fef7826970  40000ef       10        System.String  0   shared           static Empty                                 >> Domain:Value  00000000007f85a0:0000000002d41420 <<


版权声明:本文为博主原创文章,欢迎转载,仅请署名

Windbg调试WPF的依赖属性

标签:wpf   dependencyproperty   dependencyobject   windbg   依赖属性   

人气教程排行