如何在Windows上诊断堆损坏错误? [英] How do I diagnose heap corruption errors on Windows?

查看:84
本文介绍了如何在Windows上诊断堆损坏错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Windows 8.1 64位与Visual Studio 2013 Ultimate一起使用.我正在将程序从Linux移植到使用C ++,OpenGL和SDL的Windows.我在Windows的64位上通过cmake编译了适当的库自定义.当我从Visual Studio运行程序时,IDE表示头部损坏.这并不奇怪,因为我使用的是指针来实例化对象,并且我使用的是原始指针,出于参数的考虑,我确实打算将其更改为智能指针.稍后我将做增强魔术.

I'm using Windows 8.1 64-bit with Visual Studio 2013 Ultimate. I am porting a program from Linux to Windows which uses C++, OpenGL and SDL. I have the appropriate libraries custom compiled through cmake on 64-bit on Windows. When I run the program from Visual Studio, the IDE says there's a head corruption. This is no surprise since I'm using pointers to instantiate objects, and I'm using raw pointers which I do plan to change to smart pointers for the sake of the argument. I'll be doing the boost magic later.

同时,我使用我的Linux计算机诊断通过Valgrind进行的任何内存泄漏,但是Valgrind并没有严重的报告.然后,我继续使用CppCheck,但是那里也没有什么严重的问题.也许我在这里太宽容了,Windows可能实际上正在把不那么严重的东西比Linux做得更严肃,这令人惊讶,因为MSVC往往比GCC更宽容.

In the meantime, I used my Linux computer to diagnose any memory leaks through Valgrind and there was nothing serious reported from Valgrind. I then proceeded to use CppCheck but there was nothing serious on there either. Maybe I'm being too lenient here and Windows might actually be taking the less serious stuff more serious than Linux does, which is a surprise since MSVC tends to be more forgiving than GCC.

因此,该程序可在Linux上运行,而不能在Windows上运行. (太好了!)Visual Studio并没有在整个地方抛出异常的帮助,这让我更加讨厌Windows.我开始四处寻找解决方案,并遇到了称为gflags或page helper的问题,因此我安装了调试工具并尝试启动gflags,但我不知道如何使用它!然后,我后来发现您必须使用其他名为adp的工具,然后将gflags附加到它,所以当我启动adp时它崩溃了.因此,现在我不知道该怎么办,并且濒临中止端口(这很有趣,因为许多人抱怨将程序从Windows移植到Linux有多么困难,而事实恰恰相反).

So, the program works on Linux and it doesn't on Windows. (Just great!) And Visual Studio isn't helping by throwing exceptions all over the place which makes me hate Windows even more. I started googling around for a solution and came across this thing called gflags or page helper, so I installed the debugging tools and tried to launch gflags but I have no idea how to use it! I then later found that you had to use some other tool called adp and then attach gflags to it, so when I launched adp it crashes. So now I have no idea what to do and am on the verge of aborting the port (which is funny since many people are complaining how hard it is to port programs from Windows to Linux while the opposite is true).

因此,现在我向这个社区寻求帮助:如何调试/诊断Windows上发生的堆损坏错误,而不是Linux上发生的错误?我真的应该使用gflags还是应该只用胆量?

So, now I appeal to this community for help: how do I debug/diagnose heap corruption errors that occur on Windows but not on Linux? Am I really supposed to be using gflags or should I just use my guts on this?

推荐答案

使用调试堆并在main()的最开始处调用它.

Use the debug heap and call this at the very beginning in main().

_CrtSetDbgFlag(_CRTDBG_CHECK_ALWAYS_DF);

它将大大减慢程序的运行速度,但是一旦损坏就会立即中断.

It will slow down the program a lot but it should break as soon as corruption occurs.

有关详细信息,请参阅本文: https://msdn.microsoft .com/zh-CN/library/974tc9t1.aspx#BKMK_Check_for_heap_integrity_and_memory_leaks

Refer to this article for details: https://msdn.microsoft.com/en-us/library/974tc9t1.aspx#BKMK_Check_for_heap_integrity_and_memory_leaks

这篇关于如何在Windows上诊断堆损坏错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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