在Windows中检测内存损坏 [英] Detect Memory Corruption in Windows

查看:80
本文介绍了在Windows中检测内存损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过以下语句创建了内存损坏:

I created a memory corruption by the following statement:

char *msg = "Default message";
free(msg);



这将导致内存损坏异常,如下所示:



This causes the memory corruption exception as:

Break instruction exception - code 80000003 (first chance)



如何使用Windbg在Windows中检测和调试内存损坏问题?



How to detect and debug memory corruption issues in Windows probably using Windbg? What all are the windbg commands needed?

推荐答案

如果您的应用程序已经在运行并且有很多代码行,
我建议您使用Application Verifier.
另外,Rational Purifier也可以派上用场.
无需提及它们不能保证100%跟踪,这在您的情况下仍然有用.
If you have a application which is already working & with many lines of code ,
I would suggest you to use Application Verifier.
Also Rational purifier can come handy.
No need to mention that they wont guarantee 100% tracking , still might be useful in your case.


为什么不只在Visual Studio中的调试器下运行您的应用程序?当发生异常时,调试器将指向发生故障的行.

如果您确实要使用windbg,请参见此处: http://windbg.info/doc/1-common-cmds .html [ ^ ]
Why not just run your app under the debugger in Visual Studio? When an exception occurs, the debugger will point to the line that faulted.

If you really want to use windbg, see here: http://windbg.info/doc/1-common-cmds.html[^]


我有两种看待它的方式.通过调试器运行所有代码.除非您的代码完全由测试驱动,否则获得100%的代码覆盖率几乎是不可能的.另一种方法是与一些经验丰富的程序员一起设置代码审查.我的经验是,您可以找到错误模式,不仅可以识别有问题的代码,还可以识别有问题的程序员,将您引导至需要验证的热点.
如果您要处理大量代码,那么获取静态代码分析软件可能会很有帮助.
There are two ways the way I see it. Run all your code through a debugger. Getting 100% code coverage is close to impossible, unless your code is fully test-driven. The other way is to set up code review with a couple of experienced programmers. My experience is that you can find error patterns, and identify not only problematic code, but also problematic programmers, guiding you to the hot spots that needs validation.
If you have a lot of code to go through, getting a static code anlysis software might be of great help.


这篇关于在Windows中检测内存损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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