c# - 无法找到运行时 clr.dll 以使用 sos

标签 c# debugging clr windbg sos

我有一个简单的控制台应用程序(目标框架 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();
    }
}

我想查看托管堆的状态。我执行以下步骤:

  1. 打开windbg
  2. 使用 windbg 的“打开可执行文件”命令打开我的程序的 exe 文件
  3. 执行命令加载sos .load MicrosoftNet\Framework\v4.0.30319\sos.dll
  4. 执行命令查看堆状态 !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

的位置加载 sos 调试器

我曾经看过以下两门关于 C# Internals 的多元视野类(class),作者 Bart de Smet我发现它们非常适合理解 c# 和 clr 的见解:

C# Language Internals - Part 1

C# Language Internals - Part 2

关于c# - 无法找到运行时 clr.dll 以使用 sos,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41346885/

相关文章:

c# - XNA 游戏分发问题

.net - 如何在 Visual Studio 中找到堆栈跟踪?

clr - Oracle Data Provider 到 CLR 类型映射

.net - 在调试器中正确执行 .NET 语言步骤

c# - IsNullOrEmpty 错误是否已在 .NET 3.0 或更高版本中修复?

c# - 在 C# 中使用 iTextSharp 和 asp 图像调整数据库中的图像大小

c# - 如何在后台获取数据并在准备好后用数据异步更新 UI?

c# - 使用枚举作为可选参数

visual-studio-2010 - 保存 Visual Studio 调试 -> 异常设置?

linux - 如何在 Eclipse 中使用 GDB 进行 C/C++ 调试?