简体   繁体   English

Sos.dll和windbg获取引发的异常

[英]Sos.dll and windbg Get exceptions thrown

I am using sos.dll and windbg to anayze a w3wp.exe dump. 我正在使用sos.dll和windbg来分析w3wp.exe转储。 There is a high number of .Net CLR exceptions thrown per/sec shown in perfmon and i am trying to investigate this. perfmon中显示了每秒出现大量的.Net CLR异常,我正在尝试对此进行调查。 I tried doing a !dumpheap -stat -type Exception. 我尝试执行!dumpheap -stat -type异常。 But does this show the exceptions that were thrown at the instance i took the dump or does this show all the exception object instances that were created? 但这是否显示在我进行转储的实例上抛出的异常,还是显示所有已创建的异常对象实例? Exception object instances may be created without being thrown. 可以创建异常对象实例而不会引发异常。

Is there a way to just get the exceptions that were thrown? 有没有一种方法可以只获取抛出的异常?

You use the wrong tools. 您使用了错误的工具。 Install Windows Performance Toolkit which is part of the Windows 10 SDK. 安装Windows Performance Toolkit,它是Windows 10 SDK的一部分。 The 1607 SDK can be used for Win8/10 systems, the older 1511 SDK can be used for Windows 7/2008R2. 1607 SDK可用于Win8 / 10系统, 较旧的1511 SDK可用于Windows 7 / 2008R2。

Now use the WPRP profile that I posted here to capture the activity of your application by opening a cmd.exe as admin 现在,使用我在此处发布WPRP配置文件通过以管理员身份打开cmd.exe来捕获应用程序的活动

"C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\wpr.exe" -start C:\DotNetRuntime.wprp

After captured some activity of your tool, run this command to stop the capturing: 捕获工具的某些活动之后,运行以下命令以停止捕获:

"C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\wpr.exe" -stop C:\Result.etl

Now make a double click on the Result.etl to open it in Windows Performance Analyzer and load debug symbols . 现在,双击Result.etl以在Windows Performance Analyzer Result.etl其打开并加载调试符号

Now drag & drop the Generic Event graph to the analysis pane, order the colums for Provider , process , Taskname , Field 1 , Time , Opcode Name and Stack . 现在,将“ Generic Event图拖放到分析窗格中,对ProviderprocessTasknameField 1TimeOpcode NameStack进行排序。 Now filter for the Microsoft-Windows-DotNETRuntime provider and expand your process name entry and next expand the entry for Taskname Exception : 现在,筛选Microsoft-Windows-DotNETRuntime提供程序,并展开您的进程名称条目,然后展开Taskname Exception的条目:

在此处输入图片说明

Here in this demo, the VS Addon Resharper caused a JetBrains.Application.Progress.ProcessCancelledException . 在此演示中,VS Addon Resharper导致了JetBrains.Application.Progress.ProcessCancelledException Check which excceptions you see for your process and check the stack where the exceptions are raised. 检查您在处理过程中看到的错误,并检查引发异常的堆栈。

Exceptions that are thrown are first chance exceptions. 引发的异常是第一次机会异常。 Since your program does not crash, this means they are caught and handled. 由于您的程序不会崩溃,这意味着它们已被捕获并处理。

In addition to @magicandre1981's approach , I see two other options: 除了@ magicandre1981的方法之外 ,我还看到了另外两个选择:

ProcDump ProcDump

ProcDump can create crash dumps on first chance exceptions with the -e 1 command line switch. ProcDump可以使用-e 1命令行开关在第一次机会异常上创建崩溃转储。 Also define -n to specify the maximum number of dumps you want to take. 还定义-n以指定要进行的最大转储数。 Once you became aware of an exception and no longer want it to be reported, use -f to filter it. 一旦意识到异常并且不再希望报告该异常,请使用-f进行过滤。

Advantage: you do not only have the exception, you also have a call stack and all the heap information which you can analyze later. 优点:您不仅拥有异常,还拥有调用堆栈和所有堆信息,您可以在以后分析这些信息。

Disadvantage: this will significantly slow down your process and take a lot of disk space. 缺点:这将大大减慢您的处理速度并占用大量磁盘空间。

WinDbg exception commands WinDbg异常命令

You could attach WinDbg to a process and use the sxe command with the -c switch to analyze first chance exceptions. 您可以将WinDbg附加到进程,然后将sxe命令与-c开关一起使用来分析首次机会异常。 Include g in the command to continue execution. 在命令中包含g以继续执行。 It's helpful to write all output into a log file (use .logopen ). 将所有输出写入日志文件(使用.logopen )会.logopen

Example: 例:

.symfix
.reload
.logopen c:\debug\logs\firstchance.log
.loadby sos clr
ld * 
sxe -c "!pe;!clrstack;g" clr
g

.symfix and .reload may not be necessary. .symfix.reload可能不是必需的。 Just make sure your symbols are correct , otherwise all the analysis may be useless. 只需确保您的符号正确无误 ,否则所有分析可能都没有用。 The ld * will just pre-load things to make the analysis faster later on. ld *只会预加载内容,以便以后更快地进行分析。

Advantage: you can capture as many information as you want without creating huge crash dumps. 优势:您可以捕获任意数量的信息,而无需创建大量的崩溃转储。

Disadvantage: The execution of commands may significantly slow down the process. 缺点:命令的执行可能会大大减慢该过程。 WinDbg may become unstable when you do this with hundreds of exceptions. 这样做时,WinDbg可能会变得不稳定,有成百上千个例外。 (I never did this for a long time, this warning is given based on my experience with WinDbg 6.12 somewhen in 2010) (我已经很长时间没有这样做了,这个警告是根据我在2010年WinDbg 6.12的经验给出的)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM