前幾天有個朋友發個了在windows server 2008跑的IIS 跑的程序w3wp程序dmp,要我幫忙分析為何線程都掛起不運行
經過查閱資料用windbg可以調試可以輸出線程的調用堆棧,但是准備調試之前費了不少功夫和時間
主要碰到是SOS.DLL和DMP 文件運行時候的CLR.DLL不匹配問題,那就需要從w3wp運行的機器上拷貝到對應.net版本下面的sos.dll,clr.dll,mscordacwks.dll文件
然后給windbg 加載,主要是通過.load 命令,卸載擴展DLL命令是.unload ,查看當前加載的DLL命令是.chain
還需要設置好windbg 的調試符號
下載好符號后,輸入下面命令,沒出現文件不匹配提示就表示可以使用SOS.dll的擴展命令
0:000> !clrstack
OS Thread Id: 0x1cc4 (0)
Unable to walk the managed stack. The current thread is likely not a
managed thread. You can run !threads to get a list of managed threads in
the process
Failed to start stack walk: 80070057
如果出現下面情況,就是文件不匹配,你需要具體查看加載的SOS.DLL文件版本,
0:033> !clrstack The version of SOS does not match the version of CLR you are debugging. Please load the matching version of SOS for the version of CLR you are debugging. CLR Version: 4.0.30319.1008 SOS Version: 4.0.30319.1022
有時候運行機器未必 能找到對應版本的SOS.dll 你就必須要到微軟官網上面找到對應系統補丁的里面的.NET版本SOS.DLL
解壓出微軟補丁的工具msix 具體怎么用百度或者谷歌下
查閱線程 !runaway 或者!threads
0:000> !runaway
User Mode Time
Thread Time
52:13b0 0 days 0:00:23.421
41:1124 0 days 0:00:18.359
42:1cf4 0 days 0:00:11.687
44:1d64 0 days 0:00:09.390
14:13ec 0 days 0:00:07.375
16:1c08 0 days 0:00:07.171
19:1d60 0 days 0:00:06.640
18:1cc8 0 days 0:00:06.640
15:f64 0 days 0:00:06.437
17:f88 0 days 0:00:06.375
經過查閱資料 查詢所有線程調用堆棧~*e !clrstack 或者!EEStack -EE 后者的命令打印比較好看些
0:000> ~*e !clrstack
OS Thread Id: 0x954 (48)
Child SP IP Call Site
0000000011a3e538 000000007793c0ea [GCFrame: 0000000011a3e538]
0000000011a3e608 000000007793c0ea [HelperMethodFrame_1OBJ: 0000000011a3e608] System.Threading.Monitor.ObjWait(Boolean, Int32, System.Object)
0000000011a3e720 000007fe99aef61f Disruptor.BlockingWaitStrategy.WaitFor(Int64, Disruptor.Sequence, Disruptor.Sequence[], Disruptor.ISequenceBarrier)
0000000011a3e780 000007fe99aef548 Disruptor.ProcessingSequenceBarrier.WaitFor(Int64)
0000000011a3e7c0 000007fe99aeefcb Disruptor.BatchEventProcessor`1[[System.__Canon, mscorlib]].Run()
0000000011a3e840 000007fef7b3c1de System.Threading.Tasks.Task.Execute()
0000000011a3e8b0 000007fef7bed0b5 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
0000000011a3ea10 000007fef7bece19 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
0000000011a3ea40 000007fef7b3bf10 System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef)
0000000011a3eb30 000007fef7b3bca5 System.Threading.Tasks.Task.ExecuteEntry(Boolean)
0000000011a3eb70 000007fef7b2764a System.Threading.ThreadPoolWorkQueue.Dispatch()
0000000011a3f0c8 000007fef90b9e03 [DebuggerU2MCatchHandlerFrame: 0000000011a3f0c8]
0000000011a3f2a8 000007fef90b9e03 [ContextTransitionFrame: 0000000011a3f2a8]
0000000011a3f498 000007fef90b9e03 [DebuggerU2MCatchHandlerFrame: 0000000011a3f498]
0:000> !EEStack -EE
Thread 42
Current frame:
Child-SP RetAddr Caller, Callee
00000000171fd990 000007fef4402108 (MethodDesc 000007fef4132438 +0x68 System.Threading.ExecutionContextSwitcher.Undo())
00000000171fd9e0 000007fef4401c0f (MethodDesc 000007fef40104e8 +0x19f System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean))
00000000171fdd20 000007fef43e8ce0 (MethodDesc 000007fef4024840 +0xe0 System.Text.StringBuilder.Append(System.String))
00000000171fdf00 000007fef51475e2 (MethodDesc 000007fef400d340 System.Runtime.Remoting.Messaging.LogicalCallContext.Clone())
00000000171fdf50 000007fef4449282 (MethodDesc 000007fef413cd18 +0x302 System.Threading.ManualResetEventSlim.Wait(Int32, System.Threading.CancellationToken))
00000000171fe030 000007fef4449282 (MethodDesc 000007fef413cd18 +0x302 System.Threading.ManualResetEventSlim.Wait(Int32, System.Threading.CancellationToken))
00000000171fe0c0 000007fef4441bf7 (MethodDesc 000007fef4016870 +0xb7 System.Threading.Tasks.Task.SpinThenBlockingWait(Int32, System.Threading.CancellationToken))
00000000171fe130 000007fef4d89942 (MethodDesc 000007fef4016860 +0x222 System.Threading.Tasks.Task.InternalWait(Int32, System.Threading.CancellationToken))
00000000171fe150 000007fef1c4c88d (MethodDesc 000007fef1c31d58 +0x3d System.Net.Http.HttpUtilities.ContinueWithStandard[[System.__Canon, mscorlib]](System.Threading.Tasks.Task`1<System.__Canon>, System.Action`1<System.Threading.Tasks.Task`1<System.__Canon>>))
00000000171fe220 000007fef4d86687 (MethodDesc 000007fef402d0a8 +0x27 System.Threading.Tasks.Task`1[[System.__Canon, mscorlib]].GetResultCore(Boolean))
00000000171fe260 000007fe9ac40c0b (MethodDesc 000007fe9a085250 +0x1cb WebMvc.App_Start.FileUploadSDK+<>c.<UploadHTML>b__11_0(System.Object))
00000000171fe350 000007fef4401bce (MethodDesc 000007fef40104e8 +0x15e System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean))
00000000171fe420 000007fef4401a67 (MethodDesc 000007fef40104d8 +0x17 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean))
00000000171fe430 000007fef43c5eb5 (MethodDesc 000007fef4152010 +0x2e5 System.Threading.ThreadPoolWorkQueue.Dispatch())
00000000171fe450 000007fef439c0a0 (MethodDesc 000007fef402f670 +0x70 System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem())
00000000171fe490 000007fef43c5d30 (MethodDesc 000007fef4152010 +0x160 System.Threading.ThreadPoolWorkQueue.Dispatch())
00000000171fe7f0 000007fef3290a2e (MethodDesc 000007fef2ff8d38 +0x7e DomainNeutralILStubClass.IL_STUB_PInvoke(IntPtr, System.Web.RequestNotificationStatus ByRef))
00000000171fe850 000007fef322720e (MethodDesc 000007fef2fd7d90 +0x65e System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr, IntPtr, IntPtr, Int32))
00000000171fea00 000007fef3226b84 (MethodDesc 000007fef2fd7d80 +0x14 System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr, IntPtr, IntPtr, Int32))
---------------------------------------------
參考資料
https://msdn.microsoft.com/en-us/library/bb190764(v=vs.110).aspx?query=
http://www.cnblogs.com/softfair/p/The_version_SOS_not_match_version_of_CLR_PDB_symbol_for_clr_dll_not_loaded.html
https://www.cnblogs.com/zrhai/p/3784206.html