4
我如何可以遍歷引用類型(如MyClass的)和領域之一(價值型)WinDbg的.foreach引用類型,並得到字段值
我用下面的代碼獲得價值。
.foreach (address {!DumpHeap -type MyClass -short }) {!do ${address} (what I do next?) }
我得到對象的轉儲,但如何獲得所有對象的字段值?
我如何可以遍歷引用類型(如MyClass的)和領域之一(價值型)WinDbg的.foreach引用類型,並得到字段值
我用下面的代碼獲得價值。
.foreach (address {!DumpHeap -type MyClass -short }) {!do ${address} (what I do next?) }
我得到對象的轉儲,但如何獲得所有對象的字段值?
首先,你需要通過轉儲單個對象,找出各個字段的偏移量:
0:016> !do 00000000115bff60
Name: System.Action
MethodTable: 000007fedb35ff30
EEClass: 000007fedb111f90
Size: 64(0x40) bytes
(C:\Windows\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.dll)
Fields:
MT Field Offset Type VT Attr Value Name
000007fedc267680 40000ff 8 System.Object 0 instance 00000000115bff60 _target
000007fedc266138 4000100 10 ...ection.MethodBase 0 instance 0000000000000000 _methodBase
000007fedc26a798 4000101 18 System.IntPtr 1 instance 7fedf0bf238 _methodPtr
000007fedc26a798 4000102 20 System.IntPtr 1 instance 7fedf0fa850 _methodPtrAux
000007fedc267680 400010c 28 System.Object 0 instance 0000000000000000 _invocationList
000007fedc26a798 400010d 30 System.IntPtr 1 instance 0 _invocationCount
接下來,您可以使用您的循環偏移。請注意,我將-type <ClassName>
更改爲-mt <MethodTable>
以避免衝突。 !do
按子字符串搜索,其中可能包含您不期望的對象。
根據字段的類型,就可以使用d* ${address}+<offset> [L<length>]
傾倒值類型
0:016> .foreach (address {!DumpHeap -mt 000007fedb35ff30 -short }) {dp ${address}+0x20 L1}
00000000`114cfc48 00000000`114ce518
...
或!do poi(${address}+<offset>)
轉儲.NET對象
0:016> .foreach (address {!DumpHeap -mt 000007fedb35ff30 -short }) {!do poi(${address}+0x8)}
Name: PaintDotNet.Controls.UnitsComboBoxStrip
MethodTable: 000007fed94cd120
EEClass: 000007fed91b38f8
Size: 224(0xe0) bytes
(C:\Program Files\Paint.NET\PaintDotNet.exe)
Fields:
MT Field Offset Type VT Attr Value Name
000007fedc267680 400018a 8 System.Object 0 instance 0000000000000000 __identity
000007fedb6cd320 40008e0 10 ...ponentModel.ISite 0 instance 0000000000000000 site
000007fedb6fcc18 40008e1 18 ....EventHandlerList 0 instance 00000000114d0050 events
...
嗨。您需要改善問題的質量以避免降低收益。請使用正確的格式化工具代碼塊,並且還包括對您正在嘗試做什麼的一些分析。歡迎來到SO。 – canolucas 2014-08-30 21:04:23
我不知道這裏太寬泛。沒有太多的答案,一個好的答案不需要很長。唯一可能發生的事情是它是重複的。 @PhilipPittle:這與C#有關,因爲它使用SOS命令進行調試。 – 2014-09-01 11:27:30
@ThomasW。這更有意義。我會刪除我之前的評論。認爲OP的代碼示例應該是C# – 2014-09-01 11:31:20