我有一个简单的控制台应用程序(目标框架 4.5.2):
using System;
public class SosTest
{
public class Foo
{
public Foo()
{
Console.WriteLine("Creation of foo");
}
}
static void Main(string[] args)
{
var n1 = new Foo();
var n2 = new Foo();
Console.WriteLine("Allocated objects");
Console.WriteLine("Press any key to invoke GC");
Console.ReadKey();
n2 = n1;
n1 = null;
GC.Collect();
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
}
我想查看托管堆的状态。我执行以下步骤:
- 打开windbg
- 使用 windbg 的“打开可执行文件”命令打开我的程序的 exe 文件
- 执行命令加载sos
.load MicrosoftNet\Framework\v4.0.30319\sos.dll
- 执行命令查看堆状态
!eeheap -gc
但是在最后一个命令中我得到以下信息:
Failed to find runtime DLL (clr.dll), 0x80004005 Extension commands need clr.dll in order to have something to do.
为什么命令 !eeheap -gc
失败?
lm
命令的结果是否有帮助:
0:000> lm
start end module name
00be0000 00be8000 ConsoleApplication1 (deferred)
734c0000 73519000 MSCOREE (deferred)
74c20000 74d00000 KERNEL32 (deferred)
753d0000 75571000 KERNELBASE (deferred)
77d80000 77f03000 ntdll (pdb symbols)
最佳答案
我不确定你做的对不对,但我以前是用下面的命令做的:
sxe ld clrjit; g
然后写:
.loadby sos clr
sxe ld clrjit
在加载clrjit 模块 时通知调试器,g
标志用于继续执行和.loadby sos clr
将从它找到 clr.dll
我曾经看过以下两门关于 C# Internals 的多元视野类(class),作者 Bart de Smet我发现它们非常适合理解 c# 和 clr 的见解:
关于c# - 无法找到运行时 clr.dll 以使用 sos,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41346885/