zoukankan      html  css  js  c++  java
  • 转储收集和分析实用工具 (dotnet-dump) ——(microsoft介绍)

    原文地址:

    https://docs.microsoft.com/zh-cn/dotnet/core/diagnostics/dotnet-dump

    本文适用于: ✔️ .NET Core 3.0 SDK 及更高版本

     备注

    macOS 的 dotnet-dump 仅在 .NET 5.0 及更高版本中受支持。

    描述

    dotnet-dump 全局工具是在未涉及任何本机调试器(如 Linux 上的 lldb)的情况下收集和分析 Windows 和 Linux 转储的方法。 在 lldb 无法正常运行的平台(如 Alpine Linux)上,此工具非常重要。 借助 dotnet-dump 工具,可以运行 SOS 命令来分析崩溃和垃圾回收器 (GC),但它不是本机调试器,因此不支持显示本机堆栈帧之类的操作。

    dotnet-dump collect

    从进程捕获转储。

    dotnet-dump analyze

    启动交互式 shell 以了解转储。 shell 接受各种 SOS 命令

    命令函数
    soshelp 显示所有可用命令
    soshelp|help <command> 执行指定的命令。
    exit|quit 退出交互模式。
    clrstack <arguments> 仅提供托管代码的堆栈跟踪。
    clrthreads <arguments> 列出正在运行的托管线程。
    dumpasync <arguments> 显示有关垃圾回收堆上异步状态机的信息。
    dumpassembly <arguments> 显示有关程序集的详细信息。
    dumpclass <arguments> 显示有关指定地址处的 EE 类结构的信息。
    dumpdelegate <arguments> 显示有关委托的信息。
    dumpdomain <arguments> 显示所有 AppDomain 和域中的所有程序集的信息。
    dumpheap <arguments> 显示有关垃圾回收堆的信息和有关对象的收集统计信息。
    dumpil <arguments> 显示与托管方法关联的 Microsoft 中间语言 (MSIL)。
    dumplog <arguments> 将内存中压力日志的内容写入到指定文件。
    dumpmd <arguments> 显示有关指定地址处的 MethodDesc 结构的信息。
    dumpmodule <arguments> 显示有关指定地址处的 EE 模块结构的信息。
    dumpmt <arguments> 显示有关指定地址处的方法表的信息。
    dumpobj <arguments> 显示有关指定地址处的对象的信息。
    dso|dumpstackobjects <arguments> 显示在当前堆栈的边界内找到的所有托管对象。
    eeheap <arguments> 显示有关内部运行时数据结构所使用的进程内存的信息。
    finalizequeue <arguments> 显示所有已进行终结注册的对象。
    gcroot <arguments> 显示有关对指定地址处的对象的引用(或根)的信息。
    gcwhere <arguments> 显示传入参数在 GC 堆中的位置。
    ip2md <arguments> 显示 JIT 代码中指定地址处的 MethodDesc 结构。
    histclear <arguments> 释放由 hist* 命令系列使用的任何资源。
    histinit <arguments> 从保存在调试对象中的压力日志初始化 SOS 结构。
    histobj <arguments> 显示与 <arguments> 相关的垃圾回收压力日志重定位。
    histobjfind <arguments> 显示在指定地址处引用对象的所有日志项。
    histroot <arguments> 显示与指定根的提升和重定位相关的信息。
    lm|modules 显示进程中的本机模块。
    name2ee <arguments> 显示 <argument> 的 MethodTable 结构和 EEClass 结构。
    pe|printexception <arguments> 显示从地址 <argument> 处的 Exception 类派生的任何对象。
    setsymbolserver <arguments> 启用符号服务器支持
    syncblk <arguments> 显示 SyncBlock 持有者信息。
    threads|setthread <threadid> 设置或显示 SOS 命令的当前线程 ID。

    使用 dotnet-dump

    第一步是收集转储。 如果已生成核心转储,则可以跳过此步骤。 操作系统或 .NET Core 运行时的内置转储生成功能均可以创建核心转储。

    控制台
    $ dotnet-dump collect --process-id 1902
    Writing minidump to file ./core_20190226_135837
    Written 98983936 bytes (24166 pages) to core file
    Complete
    

    现在,使用 analyze 命令分析核心转储:

    控制台
    $ dotnet-dump analyze ./core_20190226_135850
    Loading core dump: ./core_20190226_135850
    Ready to process analysis commands. Type 'help' to list available commands or 'help [command]' to get detailed help on a command.
    Type 'quit' or 'exit' to exit the session.
    >

    此操作会显示一个交互式会话,该会话接受以下类似命令:

    控制台
    > clrstack
    OS Thread Id: 0x573d (0)
        Child SP               IP Call Site
    00007FFD28B42C58 00007fb22c1a8ed9 [HelperMethodFrame_PROTECTOBJ: 00007ffd28b42c58] System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean, Boolean)
    00007FFD28B42DD0 00007FB1B1334F67 System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo) [/root/coreclr/src/mscorlib/src/System/Reflection/RuntimeMethodInfo.cs @ 472]
    00007FFD28B42E20 00007FB1B18D33ED SymbolTestApp.Program.Foo4(System.String) [/home/mikem/builds/SymbolTestApp/SymbolTestApp/SymbolTestApp.cs @ 54]
    00007FFD28B42ED0 00007FB1B18D2FC4 SymbolTestApp.Program.Foo2(Int32, System.String) [/home/mikem/builds/SymbolTestApp/SymbolTestApp/SymbolTestApp.cs @ 29]
    00007FFD28B42F00 00007FB1B18D2F5A SymbolTestApp.Program.Foo1(Int32, System.String) [/home/mikem/builds/SymbolTestApp/SymbolTestApp/SymbolTestApp.cs @ 24]
    00007FFD28B42F30 00007FB1B18D168E SymbolTestApp.Program.Main(System.String[]) [/home/mikem/builds/SymbolTestApp/SymbolTestApp/SymbolTestApp.cs @ 19]
    00007FFD28B43210 00007fb22aa9cedf [GCFrame: 00007ffd28b43210]
    00007FFD28B43610 00007fb22aa9cedf [GCFrame: 00007ffd28b43610]
    

    查看已终止应用的未经处理的异常:

    控制台
    > pe -lines
    Exception object: 00007fb18c038590
    Exception type:   System.Reflection.TargetInvocationException
    Message:          Exception has been thrown by the target of an invocation.
    InnerException:   System.Exception, Use !PrintException 00007FB18C038368 to see more.
    StackTrace (generated):
    SP               IP               Function
    00007FFD28B42DD0 0000000000000000 System.Private.CoreLib.dll!System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean, Boolean)
    00007FFD28B42DD0 00007FB1B1334F67 System.Private.CoreLib.dll!System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)+0xa7 [/root/coreclr/src/mscorlib/src/System/Reflection/RuntimeMethodInfo.cs @ 472]
    00007FFD28B42E20 00007FB1B18D33ED SymbolTestApp.dll!SymbolTestApp.Program.Foo4(System.String)+0x15d [/home/mikem/builds/SymbolTestApp/SymbolTestApp/SymbolTestApp.cs @ 54]
    00007FFD28B42ED0 00007FB1B18D2FC4 SymbolTestApp.dll!SymbolTestApp.Program.Foo2(Int32, System.String)+0x34 [/home/mikem/builds/SymbolTestApp/SymbolTestApp/SymbolTestApp.cs @ 29]
    00007FFD28B42F00 00007FB1B18D2F5A SymbolTestApp.dll!SymbolTestApp.Program.Foo1(Int32, System.String)+0x3a [/home/mikem/builds/SymbolTestApp/SymbolTestApp/SymbolTestApp.cs @ 24]
    00007FFD28B42F30 00007FB1B18D168E SymbolTestApp.dll!SymbolTestApp.Program.Main(System.String[])+0x6e [/home/mikem/builds/SymbolTestApp/SymbolTestApp/SymbolTestApp.cs @ 19]
    
    StackTraceString: <none>
    HResult: 80131604

    Docker 的特殊说明

    如果在 Docker 下运行,则转储集合需要 SYS_PTRACE 功能(--cap-add=SYS_PTRACE 或 --privileged)。

    在 Microsoft .NET Core SDK Linux Docker 映像上,某些 dotnet-dump 命令可能会引发以下异常:

    未经处理的异常:System.DllNotFoundException:无法加载共享库“libdl.so”或其依赖项之一的异常。

    若要解决此问题,请安装“libc6-dev”包。

  • 相关阅读:
    XSS
    XSS
    检查空引用
    LockInt
    Unity Shaderlab: Object Outlines 转
    git 恢复单个文件的历史版本
    烽火HG220G-U E00L2.03M2000光猫改桥接教程
    mark mem
    转 class和struct最本质的区别
    unity shader base pass and additional pass
  • 原文地址:https://www.cnblogs.com/panpanwelcome/p/14267445.html
Copyright © 2011-2022 走看看