如何调试/修复访问冲突(堆损坏)
从 VS2005 迁移到 VS2008 (win32) 后,我的应用程序崩溃(反复)。
如果我进入调试器,我会得到:
Access violation reading location 0x00000014
首先,我看到崩溃行的类对象有一个 NULL _vptr。但同一类的其他一些对象具有非 NULL _vprt :)
其次,如果我更改成员对象声明的顺序,则崩溃会移动到其他行。
所以我猜这一定是一个损坏的堆问题。
你同意?如果是,堆栈中的分配数量(例如“char buffer[8192]”)是否会成为问题?
我尝试过purify、应用程序验证程序,但没有成功。我的应用程序是一个位于专有应用程序中的插件(dll)。我只能附加调试器。
预先感谢,
保罗
My app crashes (repeatably) after I have moved from VS2005 to VS2008 (win32).
If I step in the debugger, I get:
Access violation reading location 0x00000014
Firstly, I see that the class object at the crash line, has a NULL _vptr. But some other objects of the same class have non-NULL _vprt :)
Secondly, if I change the order of the member object declarations, the crash moves to some other line.
So I guess this must be a corrupt heap problem.
Do you agree? if yes, could the number of allocations in the stack such as "char buffer[8192]" be a problem?
I have tried purify, application verifier without luck. My app is a plugin (dll) living in a proprietary application. I can only attach with a debugger.
Thanks in advance,
Paul
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你同意吗?如果是,堆栈中的分配数量(例如
char buffer[8192]
)是否会成为问题?是的,堆损坏可能是由在堆上分配的巨大数组引起的(通过使用 new 或 malloc)。如果你在Stack上创建一个巨大的数组,如果相邻的内存被分配给另一个对象,程序将覆盖该对象的数据,从而导致崩溃。因此,两者都可能是危险的,但由于不同的问题。如果您谈论的是堆栈数组,不,它不会导致堆损坏,因为堆栈或堆(而不是 C++ 中的自由存储)是两个不同的内存实体。
堆损坏可能非常令人沮丧并且难以诊断。尽管有多种方法可以尝试调试此类错误,但没有明确的步骤来解决此类问题。
使用 Microsoft Windows 调试工具调试 Visual C++ 中的堆损坏 是一个优秀的源代码,记录了特定于 Visual C++ 的技术
Do you agree? if yes, could the number of allocations in the stack such as
char buffer[8192]
be a problem?Yes, Heap corruption can be caused by an array of huge sizes allocated on Heap(by using new or malloc). If you are creating an huge sized array on Stack, If the adjacent memory is allocated to another object, the program will overwrite that object's data, resulting in crashes. So both might be hazardous but due to different problems. If you are talking about an stack array, No it cannot cause heap corruption simply because stack or heap(rather free store in C++) are two different memory entities.
Heap corruptions can be very frustrating and difficult to diagnose. And there are not definite steps to solve such a problem though there are number of methods which one can try to debug such errors.
Debugging Heap Corruption in Visual C++ Using Microsoft Debugging Tools for Windows is an excellent source which documents techniques specific to visual c++
这绝对看起来像是堆损坏 - 在某些时候,您的代码在对象顶部写入零,从而杀死了 vptr。从VS2005迁移到VS2008后发生这种情况的原因可能是因为堆布局发生了一些变化。该错误可能也出现在 VS2005 中,但其造成的损害却未被注意到。
使用您提到的工具通常可以解决此类问题。您在使用它们时遇到过哪些不走运的情况?
既然您说您的应用程序重复以相同的方式崩溃,您可以在代码中添加检查。不断验证损坏的物体(确保其开头未归零),并在观察到损坏时进行破坏。查看最近一次成功验证和中断之间的活动将有助于您集中注意力。请记住,堆使用情况的任何变化都可能隐藏问题,即损坏其他位置。
This definitively looks like a heap corruption - at some point, your code write zeros on the top of the object, and that kills the vptr. The reason it happens after moving from VS2005 to VS2008 is probably because the heap layout has somewhat changed. The bug was probably in VS2005 as well, but its damage was unnoticed.
Using the tools you mention usually solves such problems. What kind of no luck have you had when using them?
Since you say your app repeatedly crashes in the same way, you can add checks in your code. Continuously verify the damaged object (make sure its beginning wasn't zeroed), and break when you observe a damage. Looking at the activity between the latest successful validation and the break would help you focus. Just have in mind that any change in heap usage might hide the problem, namely corrupt some other location.
事实证明,这是一个与我的应用程序及其某些依赖项(库)之间的预处理器定义不同相关的问题。
This turned out to be an issue related to preprocessor defines being different between my app and some of its dependencies (libs).