使用WinDbg并尝试调试Silverlight应用程序的内存泄漏,我在我的对象上遇到了作为DependencyProperty实现的属性 - 当我在调试器(WinDbg)中转储对象时,我可以看到属性 - 这是,我可以看到实际的静态场。
如何查看属性的实际值?
答案 0 :(得分:3)
这很大程度上依赖于对其他版本中可能会有所不同的未记录内部构造的假设,但是举例来说,这里是如何使用.NET 4获取WPF中窗口的Title属性的值,这里我记得所以我可以找到再次与Google合作。
首先,找到System.Windows.Window.TitleProperty
的值的地址:
0:000> !name2ee *!System.Windows.Window ... Module: 54b81000 Assembly: PresentationFramework.dll Token: 0200009c MethodTable: 54f06b54 EEClass: 54ba12bc <--- Remember this Name: System.Windows.Window ... 0:000> !DumpClass /d 54ba12bc <--- EEClass value from above ... 62887fec 40002f1 4cc ...ependencyProperty 0 static 020e724c TitleProperty ... ^^^^^^^^ Property object address
现在,获取GlobalIndex
,这是_packedData
字段的最后16位:
0:000> !DumpObj /d 020e724c <--- Property object address from above ... 62a9c190 4001377 20 System.Int32 1 instance 262372 _packedData ... ^^^^^^ & 0xffff == 228
所以228是GlobalIndex
。
现在找到窗口的地址:
0:000> !name2ee *!Your.Window.Class.Name ... Module: 00122e9c Assembly: YourAssembly.exe Token: 020001fc MethodTable: 002a4068 <--- Remember this EEClass: 00297504 Name: Your.Window.Class.Name ... 0:000> !dumpheap -mt 002a4068 <--- Remember this Address MT Size 020e6b6c 002a4068 456 <--- If >1 object found, you must pick the right one. ...
窗口位于020e6b6c。您要查找的值位于_effectiveValues
数组中的某个位置:
0:000> !DumpObj /d 020e6b6c ... 6288e394 4001359 10 ...ctiveValueEntry[] 0 instance 0912e08c _effectiveValues ... ^^^^^^^^ Array address 0:000> !DumpArray -details 0912e08c ... [18] 0912e124 Name: System.Windows.EffectiveValueEntry MethodTable: 6288978c EEClass: 627bda2c Size: 16(0x10) 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 57bcf568 40013a7 0 System.Object 0 instance 091df9c8 _value 57bd4798 40013a8 4 System.Int16 1 instance 228 _propertyIndex 62a9c360 40013a9 6 System.Int16 1 instance 27 _source ...
数组按_propertyIndex
字段的值排序(除了_propertyIndex == -1
末尾的一些空条目外),因此不难找到_propertyIndex
的条目228
最后,转储相应的_value
字段:
0:000> !DumpObj /d 091df9c8 ... 57bcf568 40013c0 4 System.Object 0 instance 020f6228 _baseValue 57bcf568 40013c1 8 System.Object 0 instance 091df92c _expressionValue 57bcf568 40013c2 c System.Object 0 instance 00000000 _animatedValue 57bcf568 40013c3 10 System.Object 0 instance 00000000 _coercedValue ... 0:000> !DumpObj /d 020f6228 <--- From _baseValue, gives the binding expression ... Name: System.Windows.Data.BindingExpression ... 0:000> !DumpObj /d 091df92c <--- From _expressionValue, gives the actual value ... String: YOUR WINDOW TITLE ...
呜呜。
答案 1 :(得分:1)
您应该能够使用DependencyObject上的GetValue(PropertyName)方法获取值(这是它具有依赖项属性所必需的)。不确定它是否适用于WinDbg。 Tess Ferrandez mentions one tip with Dependency Properties但它没有给出真正的答案。
答案 2 :(得分:1)
要获得完整的解决方案,请尝试以下分步指南:http://georgelache.blogspot.ro/2012/04/steps-to-get-value-of-dependency.html
该示例涵盖了获取窗口标题的情况
!CLRStack -a
...
0000000000129270 000006442d6acf50 System.Windows.Window.InternalClose(Boolean,Boolean)
PARAMETERS:
this (0x0000000000129360) = 0x0000000011b59968
shutdown = <no data>
ignoreCancel = <no data>
LOCALS:
<no data>
<no data>
<no data>
...
0:000&GT; !做 0x0000000011b59968
名称:GFW.Controls.View.ShellWindow MethodTable:00000644805228b8 EEClass:0000064480516240 大小:832(0x340)字节 ...
00000644319b3708 40002d3 998 ... ependencyProperty 0 static 00000000115de6d8 TitleProperty 00000644319be898 4001323 20 ... ctiveValueEntry [] 0实例 00000000154ff638 _effectiveValues ...
0:000&GT; !do / d 00000000115de6d8
名称:System.Windows.DependencyProperty
MethodTable:00000644319b3708
EEClass:0000064431857550
大小:88(0x58)字节
文件:C:\ WINDOWS \ Microsoft.Net \ assembly \ GAC_MSIL \ WindowsBase \ v4.0_4.0.0.0__31bf3856ad364e35 \ WindowsBase.dll
字段:
MT Field Offset Type VT Attr Value Name
00000644784c6960 400133c 8 System.String 0 instance 00000000111f6450 _name
00000644784c82e8 400133d 10 System.Type 0 instance 0000000011024538 _propertyType
00000644784c82e8 400133e 18 System.Type 0 instance 0000000011255ea8 _ownerType
00000644319b12a8 400133f 20 .... PropertyMetadata 0实例00000000115de678 _defaultMetadata
00000644319b1088 4001340 28 ... dateValueCallback 0 instance 00000000115de638 _validateValueCallback
00000644319be750 4001341 30 ... ndencyPropertyKey 0实例0000000000000000 _readOnlyKey
0000064431c147f8 4001342 40 System.Int32 1实例 262462 _packedData
00000644319be408 4001343 48 .... InsertionSortMap 1实例00000000115de720 _metadataMap
00000644319b0fc8 4001344 38 ... erceValueCallback 0 instance 0000000000000000 _designerCoerceValueCallback
00000644784c5ab8 400133b 808 System.Object 0 static 000000001102f290 UnsetValue
00000644319bc6c0 4001345 800 ... ty,WindowsBase]] 1 static 0000000021033b88 RegisteredPropertyList
00000644784d1c28 4001346 810 ... ections.Hashtable 0 static 0000000011030aa8 PropertyFromName
00000644784cc848 4001347 5c8 System.Int32 1 static 1290 GlobalIndexCount
00000644784c5ab8 4001348 818 System.Object 0 static 00000000110407e8 Synchronized
00000644784c82e8 4001349 820 System.Type 0 static 0000000011040800 NullableType
GlobalIndex:获取该物业的索引: 262462 &amp; 0xFFFF(使用Windows计算器)= 318
!DumpArray -details 00000000154ff638
[31] 00000000154ff838
Name: System.Windows.EffectiveValueEntry
MethodTable: 00000644319b6120
EEClass: 0000064431858c90
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
00000644784c5ab8 400136e 0 System.Object 0 instance 0000000041dd7b88 _value
00000644784d0930 400136f 8 System.Int16 1 instance 318 _propertyIndex
0000064431c149b0 4001370 a System.Int16 1 instance 11 _source
0:000&GT; !do / d 0000000041dd7b88
名称:System.String
MethodTable:00000644784c6960
EEClass:000006447804eec8
大小:108(0x6c)字节
文件:C:\ WINDOWS \ Microsoft.Net \ assembly \ GAC_64 \ mscorlib \ v4.0_4.0.0.0__b77a5c561934e089 \ mscorlib.dll
字符串:我的窗口标题