WinDbg/SOS:如何将 !threads 命令中的托管线程与 System.Threading.Thread 实例关联起来
使用 WinDbg 和 SOS,我有以下问题:
0:011> !threads
ThreadCount: 7
UnstartedThread: 0
BackgroundThread: 4
PendingThread: 0
DeadThread: 2
PreEmptive GC Alloc Lock
ID ThreadOBJ State GC Context Domain Count APT Exception
0 618 0015b350 20 Enabled 00000000:00000000 0017b720 0 Ukn
2 624 0016f508 b220 Enabled 00000000:00000000 0017b720 0 MTA (Finalizer)
9 e48 001c13d0 1220 Enabled 00000000:00000000 0017b720 0 Ukn
10 e8c 048c6a40 1800220 Enabled 00c296a8:00c2ab44 0017b720 0 MTA (Threadpool Worker) System.NullReferenceException
XXX 0 00224138 1820 Enabled 00000000:00000000 0017b720 0 MTA
XXX 0 001d5b50 1820 Enabled 00000000:00000000 0017b720 0 Ukn
11 564 00166318 1800220 Enabled 00c2cf30:00c2eb44 0017b720 0 MTA (Threadpool Worker)
0:011> !dumpheap -type System.Threading.Thread
Address MT Size
00b16478 79bba7a4 60
00b41a7c 79bca7ac 28
00b41a98 79bba7a4 60
00b41ecc 79bba7a4 60
00bf1e20 79bca7ac 28
00bf1e3c 79bba7a4 60
00c03b34 79bca7ac 28
00c03b50 79bba7a4 60
total 8 objects
Statistics:
MT Count TotalSize Class Name
79bca7ac 3 84 System.Threading.ThreadStart
79bba7a4 5 300 System.Threading.Thread
Total 8 objects
我的问题是:如何确定堆上的哪些 System.Threading.Thread 实例对应于实际执行的托管线程。
更新: 这是调试 .NET 1.1 应用程序。 在此版本中,我从 !DumpObj 得到这样的输出
0:000> !dumpobj 00b16478
Name: System.Threading.Thread
MethodTable 0x79bba7a4
EEClass 0x79bba9d4
Size 60(0x3c) bytes
mdToken: 020000ec (c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll)
FieldDesc*: 79bbaa38
MT Field Offset Type Attr Value Name
79bba7a4 4000337 4 CLASS instance 00000000 m_Context
79bba7a4 4000338 8 CLASS instance 00000000 m_LogicalCallContext
79bba7a4 4000339 c CLASS instance 00000000 m_IllogicalCallContext
79bba7a4 400033a 10 CLASS instance 00000000 m_Name
79bba7a4 400033b 14 CLASS instance 00000000 m_ExceptionStateInfo
79bba7a4 400033c 18 CLASS instance 00000000 m_Delegate
79bba7a4 400033d 1c CLASS instance 00000000 m_PrincipalSlot
79bba7a4 400033e 20 CLASS instance 00000000 m_ThreadStaticsBuckets
79bba7a4 400033f 24 CLASS instance 00000000 m_ThreadStaticsBits
79bba7a4 4000340 28 CLASS instance 00000000 m_CurrentCulture
79bba7a4 4000341 2c CLASS instance 00000000 m_CurrentUICulture
79bba7a4 4000342 30 System.Int32 instance 2 m_Priority
79bba7a4 4000343 34 System.Int32 instance 1422160 DONT_USE_InternalThread
79bba7a4 4000344 0 CLASS shared static m_LocalDataStoreMgr
>> Domain:Value 0017b720:00b162e8 <<
Using WinDbg and SOS, I have the following:
0:011> !threads
ThreadCount: 7
UnstartedThread: 0
BackgroundThread: 4
PendingThread: 0
DeadThread: 2
PreEmptive GC Alloc Lock
ID ThreadOBJ State GC Context Domain Count APT Exception
0 618 0015b350 20 Enabled 00000000:00000000 0017b720 0 Ukn
2 624 0016f508 b220 Enabled 00000000:00000000 0017b720 0 MTA (Finalizer)
9 e48 001c13d0 1220 Enabled 00000000:00000000 0017b720 0 Ukn
10 e8c 048c6a40 1800220 Enabled 00c296a8:00c2ab44 0017b720 0 MTA (Threadpool Worker) System.NullReferenceException
XXX 0 00224138 1820 Enabled 00000000:00000000 0017b720 0 MTA
XXX 0 001d5b50 1820 Enabled 00000000:00000000 0017b720 0 Ukn
11 564 00166318 1800220 Enabled 00c2cf30:00c2eb44 0017b720 0 MTA (Threadpool Worker)
0:011> !dumpheap -type System.Threading.Thread
Address MT Size
00b16478 79bba7a4 60
00b41a7c 79bca7ac 28
00b41a98 79bba7a4 60
00b41ecc 79bba7a4 60
00bf1e20 79bca7ac 28
00bf1e3c 79bba7a4 60
00c03b34 79bca7ac 28
00c03b50 79bba7a4 60
total 8 objects
Statistics:
MT Count TotalSize Class Name
79bca7ac 3 84 System.Threading.ThreadStart
79bba7a4 5 300 System.Threading.Thread
Total 8 objects
My question is: how can I determine which instances of System.Threading.Thread on the heap correspond to which of the managed threads actually executing.
Updated:
This is debugging a .NET 1.1 application.
In this version I get output like this from !DumpObj
0:000> !dumpobj 00b16478
Name: System.Threading.Thread
MethodTable 0x79bba7a4
EEClass 0x79bba9d4
Size 60(0x3c) bytes
mdToken: 020000ec (c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll)
FieldDesc*: 79bbaa38
MT Field Offset Type Attr Value Name
79bba7a4 4000337 4 CLASS instance 00000000 m_Context
79bba7a4 4000338 8 CLASS instance 00000000 m_LogicalCallContext
79bba7a4 4000339 c CLASS instance 00000000 m_IllogicalCallContext
79bba7a4 400033a 10 CLASS instance 00000000 m_Name
79bba7a4 400033b 14 CLASS instance 00000000 m_ExceptionStateInfo
79bba7a4 400033c 18 CLASS instance 00000000 m_Delegate
79bba7a4 400033d 1c CLASS instance 00000000 m_PrincipalSlot
79bba7a4 400033e 20 CLASS instance 00000000 m_ThreadStaticsBuckets
79bba7a4 400033f 24 CLASS instance 00000000 m_ThreadStaticsBits
79bba7a4 4000340 28 CLASS instance 00000000 m_CurrentCulture
79bba7a4 4000341 2c CLASS instance 00000000 m_CurrentUICulture
79bba7a4 4000342 30 System.Int32 instance 2 m_Priority
79bba7a4 4000343 34 System.Int32 instance 1422160 DONT_USE_InternalThread
79bba7a4 4000344 0 CLASS shared static m_LocalDataStoreMgr
>> Domain:Value 0017b720:00b162e8 <<
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
托管线程有一个成员变量 m_ManagedThreadId
m_ManagedThreadID 对应于 !threads 输出中的“ID”
这是一个简单的脚本来转储托管线程对象及其 id
这是上面 .foreach 的输出
The managed thread has a member variable m_ManagedThreadId
The m_ManagedThreadID corresponds to the "ID" in the !threads output
And here is a simple script to dump the managed thread object and its id
Here is the output from the above .foreach
我现在看到
System.Threading.Thread
对象的DONT_USE_InternalThread
字段的值是标题ThreadOBJ
下出现的十六进制值的十进制等效值!threads
输出中的 code>。I now see that the value of the
DONT_USE_InternalThread
field of mySystem.Threading.Thread
object is the decimal equivalent of the hex value appearing under the headingThreadOBJ
in the!threads
output.