调试 winform 崩溃 - C# [ADPlus +风数据库]
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、记事本等。
经过一些 - search - 根据 Microsoft 那个人提供的建议,我尝试使用 ADPlus 来获取内存转储和内存转储。 Windbg 来分析,但是我从 Windbg 获得的信息比异常本身更加神秘。
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=????????
可能有一些专家可以理解这些信息,但我不能。
那么,你们是如何分析这类问题的呢?有类似 .Net 的“JVM 堆转储分析器”之类的东西吗?
环境:Windows XP SP3 [完全访问权限,管理员]
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:
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.
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.
So, what do you guys do to analyse thse kind of problems? Anything like a "heap dump analyser for JVM" for .Net ?
Environment: Windows XP SP3 [full access, admin]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Visual Studio 中,转到项目属性并启用“非托管代码调试”,然后启动调试器。
[不确定是否需要以下步骤,但我刚刚做到了]
在 Visual Studio 的立即窗口中执行 .load SOS.dll
我能够找到问题的根本原因:对类型为“ABC.Form1+SendMessageDelegate”的垃圾收集委托进行了回调::调用'。这可能会导致应用程序崩溃、损坏和数据丢失。将委托传递给非托管代码时,托管应用程序必须使它们保持活动状态,直到保证它们永远不会被调用。
感谢所有发布回复或评论的人。
In Visual Studio, go to project properties and enable "unmanaged code degubbing" then start the debugger.
[not sure if below step is required but I just did it]
execute .load SOS.dll in Immediate Window of visual studio
I was able find the root cause of the problem: A callback was made on a garbage collected delegate of type 'ABC.Form1+SendMessageDelegate::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.
Thanks everyone who posted a reply or comments.