调试Winform崩溃-C#[ADPlus + Windbg] [英] Debugging winform crash - C# [ADPlus + Windbg]

查看:495
本文介绍了调试Winform崩溃-C#[ADPlus + Windbg]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


 System.AccessViolationException was unhandled
  Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
  Source=System.Windows.Forms
  StackTrace:
       at System.Windows.Forms.UnsafeNativeMethods.PeekMessage(MSG& msg, HandleRef hwnd, Int32 msgMin, Int32 msgMax, Int32 remove)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at ABC.Program.Main() in C:\Documents and Settings\...\Program.cs:line 17
  InnerException: 

这个很难重现的异常是非常不可预测的.我连接了Visual Studio调试器并运行了7-10次测试,并能够成功捕获此堆栈跟踪.请注意,这些都不是我的代码,因此在Windows级别发生了一些怪异的事情.顺便说一句,我们使用PInvoke打开/关闭iexplore,记事本等窗口.

This, hard to reproduce exception, is very unpredictable. I attached my visual studio debugger and ran the test 7-10 times and was able to successfully capture this stack trace. Notice that none of this is my code, so something spooky happening at windows level. BTW we use PInvoke to open / close windows like iexplore, notepad etc.

经过一段时间-搜索-并且根据微软那个家伙的建议,我尝试了ADPlus来获取内存转储& Windbg进行分析,但是我从windbg获得的信息比异常本身更加神秘.

After some - search - and based upon the advice give by that guy from Microsoft I tried ADPlus to get the memory dump & Windbg to analyse, but the information I get from the windbg is even more cryptic than the exception itself.


This dump file has an exception of interest stored in it.
The stored exception information can be accessed via .ecxr.
(904.1cf4): Access violation - code c0000005 (first/second chance not available)
eax=003c4d10 ebx=00000000 ecx=00000000 edx=00000000 esi=003c4d2a edi=0012f1a0
eip=003c4b64 esp=0012f11c ebp=0012f138 iopl=0         nv up ei pl zr na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010246
003c4b64 8b410c          mov     eax,dword ptr [ecx+0Ch] ds:0023:0000000c=????????
0:000> .ecxr
eax=003c4d10 ebx=00000000 ecx=00000000 edx=00000000 esi=003c4d2a edi=0012f1a0
eip=003c4b64 esp=0012f11c ebp=0012f138 iopl=0         nv up ei pl zr na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010246
003c4b64 8b410c          mov     eax,dword ptr [ecx+0Ch] ds:0023:0000000c=????????

可能有些专家可以提供这些信息,我不能.

There can be some experts which can make sence of this information, I cannot.

那么,你们如何分析此类问题?像.Net的"JVM堆转储分析器"之类的东西?

环境:Windows XP SP3 [完全访问权限,管理员]

Environment: Windows XP SP3 [full access, admin]

推荐答案

在Visual Studio中,转到项目属性并启用非托管代码脱胶",然后启动调试器.

In Visual Studio, go to project properties and enable "unmanaged code degubbing" then start the debugger.

[不确定是否需要执行以下步骤,但我只是这样做了] 在Visual Studio的即时窗口中执行.load SOS.dll

[not sure if below step is required but I just did it] execute .load SOS.dll in Immediate Window of visual studio

我能够找到问题的根本原因:对类型为'ABC.Form1 + SendMessageDelegate :: Invoke'的垃圾收集委托进行了回调.这可能会导致应用程序崩溃,损坏和数据丢失.将委托传递给非托管代码时,托管应用程序必须使它们保持活动状态,直到确保永远不会调用它们为止.

感谢所有发表回复或评论的人.

Thanks everyone who posted a reply or comments.

这篇关于调试Winform崩溃-C#[ADPlus + Windbg]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆