c# - 使用 windbg 调试 .NET 转储

标签 c# .net windows windbg

我制作了一个 .NET 进程的转储(使用 -ma 选项和 procdump.exe 中的高 CPU 触发器),我想在运行的线程中查看有关我的代码正在做什么的线索。我明白了:

*** procdump  -ma -c 65 -s 2 -n 3 service.exe
*** Process exceeded 65% CPU for 2 seconds. Thread consuming CPU: 4396 (0x112c)'

指示的线程在转储时正在执行:

0:022> k
ChildEBP RetAddr  
WARNING: Frame IP not in any known module. Following frames may be wrong.
0990f104 040666ab 0x40656f8
0990f124 04066465 0x40666ab
0990f14c 040655e2 0x4066465
0990f160 040651f4 0x40655e2
0990f178 04065032 0x40651f4
0990f1a4 04064ee5 0x4065032
0990f1c8 04062705 0x4064ee5
0990f20c 04062512 0x4062705
*** WARNING: Unable to verify checksum for System.ServiceModel.ni.dll
0990f31c 6caf0cab 0x4062512
0990f3d0 6caeebf6 System_ServiceModel_ni+0x3b0cab
0990f43c 6caee962 System_ServiceModel_ni+0x3aebf6
0990f474 6caee5cb System_ServiceModel_ni+0x3ae962
0990f488 6caed407 System_ServiceModel_ni+0x3ae5cb
0990f4d4 6cb07a4d System_ServiceModel_ni+0x3ad407
0990f4f4 6d24c989 System_ServiceModel_ni+0x3c7a4d
0990f510 6d24c966 System_ServiceModel_ni+0xb0c989
*** WARNING: Unable to verify checksum for mscorlib.ni.dll
0990f584 6f8c4096 System_ServiceModel_ni+0xb0c966
0990f598 6f8ee1a0 mscorlib_ni+0x364096
0990f5b4 6f8ed949 mscorlib_ni+0x38e1a0
0990f604 6f8ed7f5 mscorlib_ni+0x38d949
0990f614 705a3315 mscorlib_ni+0x38d7f5
0990f668 705a6cdf clr!CallDescrWorkerWithHandler+0x6b
0990f6dc 70741281 clr!MethodDescCallSite::CallTargetWorker+0x152
0990f754 706082f7 clr!QueueUserWorkItemManagedCallback+0x1f
0990f76c 70608365 clr!Thread::DoExtraWorkForFinalizer+0x1ca
0990f814 70608432 clr!Thread::DoExtraWorkForFinalizer+0x256
0990f870 7060849f clr!Thread::DoExtraWorkForFinalizer+0x615
0990f894 70741219 clr!Thread::DoExtraWorkForFinalizer+0x6b2
0990f948 70740b31 clr!ManagedPerAppDomainTPCount::DispatchWorkItem+0xc5
0990f95c 70741711 clr!ThreadpoolMgr::ExecuteWorkRequest+0x42
0990f9c4 707236f8 clr!ThreadpoolMgr::WorkerThreadStart+0x353
0990fddc 76f9336a clr!Thread::intermediateThreadProc+0x4d
0990fde8 77bd9f72 kernel32!BaseThreadInitThunk+0xe
0990fe28 77bd9f45 ntdll!__RtlUserThreadStart+0x70
0990fe40 00000000 ntdll!_RtlUserThreadStart+0x1b

问题是在线程池线程执行时,我没有在堆栈中看到任何“我的代码”,以了解它在做什么。

最佳答案

不幸的是,.net 不遵守 Windows 部门制定的规则,它按照自己的方式行事(就像 Microsoft 开发部门所做的很多事情一样)。因此,您无法获得与 native 应用程序相同的调试信息。

当我使用 windbg、spy 或 dumpbin 这些在过去非常宝贵的工具时,这让我非常头疼。但没关系,你可以从中得到一些东西:

首先您需要加载 sos 信息,然后您可以使用 !clrstack 查看 .net 堆栈跟踪。

.loadby sos mscorwks (for .net 2)
.loadby sos clr (for .net 4, of course :( )
!clrstack

有一个 cheat sheet一些有用的命令。

关于c# - 使用 windbg 调试 .NET 转储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22839099/

相关文章:

c# - 操作无法完成。该系统找不到指定的路径

.net - 是否有任何 .NET ORM 使用构造函数 "properly"?

c# - 错误 CS0433 "Type ' X' already exists in both A.dll and B.dll "来自哪里?

.net - 我应该选择 N 层架构而不是 MVC 吗?

c++ - 验证库 (.lib) 中使用的 CRT

c# - Console.WriteLine() 如何知道如何将对象转换为字符串

c# - postman 以 json 和图像发送数据

c++ - 通过注册表递归的最佳方法 (C++)?

ruby - 用ruby查询windows上已安装的软件

c# - 我正在尝试使用NAudio创建效果Delay