我写了一个简单的C#应用:
static void Main(string[] args)
{
var list = new List<int> {500,400,300,200,100};
var listEnumerator = list.GetEnumerator();
listEnumerator.MoveNext();
} // <--- breakpoint here我在最后设置了一个断点,用Visual Studio运行它,然后启动windbg并附加到进程(选中了“非侵入性”复选框)。
然后我输入了以下命令:
.load C:\Program Files (x86)\Windows Kits\8.0\Debuggers\x86\sosex.dll
!mframe 17
!mdt listEnumerator我得到的输出显然是错误的(字段都乱七八糟的,它似乎报告了'current‘下的index的值,'version’下的'current‘的值,以及'index’下的version‘的值。它只对了一个字段--第一个。
Local #0: (System.Collections.Generic.List`1+Enumerator) VALTYPE (MT=72dfd838, ADDR=0029efb8)
list:02632464 (System.Collections.Generic.List`1[[System.Int32, mscorlib]])
index:0x5 (System.Int32)
version:0x1f4 (System.Int32)
current:00000001 (T)然后我尝试使用SOS的!DumpVC,但得到了同样的混淆:
0:000> !DumpVC 72dfd838 0029efb8
Name: System.Collections.Generic.List`1+Enumerator
MethodTable: 72dfd838
EEClass: 72a32d38
Size: 24(0x18) bytes
File: C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll
Fields:
MT Field Offset Type VT Attr Value Name
736ae16c 4000c99 0 ...Generic.List`1[T] 0 instance 02632464 list
72e03aa4 4000c9a 8 System.Int32 1 instance 5 index
72e03aa4 4000c9b c System.Int32 1 instance 500 version
00000000 4000c9c 4 VAR 0 instance 00000001 current这一切为什么要发生?
发布于 2014-02-07 05:46:54
问题是CLR对闭合类型的枚举器结构的字段进行了重新排序(int的枚举器),因此它们与开放类型(T的枚举器)不匹配。Sosex使用开放类型而不是封闭类型来读取字段。sosex中的这个bug现在已经被修复了。
https://stackoverflow.com/questions/21613938
复制相似问题