/ MT和/ MD建立崩溃,但只有当未安装调试器:如何调试? [英] /MT and /MD builds crashing, but only when debugger isn't attached: how to debug?

查看:188
本文介绍了/ MT和/ MD建立崩溃,但只有当未安装调试器:如何调试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小的单线程C ++应用程序,编译和使用Visual Studio 2005,使用升压(CRC,program_options和分词),STL一知半解,以及各种其他系统头相连。

I have a small single-threaded C++ application, compiled and linked using Visual Studio 2005, that uses boost (crc, program_options, and tokenizer), a smattering of STL, and assorted other system headers.

(它的主要目的是在.csv阅读并生成一个自定义的二进制.DAT和配对的.h声明结构,解释中的.dat的格式。)

(It's primary purpose is to read in a .csv and generate a custom binary .dat and a paired .h declaring structures that "explain" the format of the .dat.)

工具崩溃(访问冲突的NULL)时,在调试器外部仅在发布运行。例如。 pressing F5不会导致工具崩溃,按Ctrl-F5一样。当我重新连接调试器,我得到这个堆栈:

The tool is crashing (access violation on NULL) when run outside the debugger, only in release. E.g. pressing F5 does not cause the tool to crash, Ctrl-F5 does. When I re-attach the debugger, I get this stack:

ntdll.dll!_RtlAllocateHeap@12()  + 0x26916 bytes    
csv2bin.exe!malloc(unsigned int size=0x00000014)  Line 163 + 0x63 bytes C
csv2bin.exe!operator new(unsigned int size=0x00000014)  Line 59 + 0x8 bytes C++
>csv2bin.exe!Record::addField(const char * string=0x0034aac8)  Line 62 + 0x7 bytes  C++
csv2bin.exe!main(int argc=0x00000007, char * * argv=0x00343998)  Line 253   C++
csv2bin.exe!__tmainCRTStartup()  Line 327 + 0x12 bytes  C

它的轰然上线是一个有点看似平淡无奇的配置:

The line it's crashing on is a somewhat innocuous-looking allocation:

pField = new NumberField(this, static_cast<NumberFieldInfo*>(pFieldInfo));

...我不相信它已经达到了构造的是,它跳转到构造函数之前刚刚分配内存。它也通过它崩溃,通常是一致的(但其他非可疑的)位置的时间执行该code数十次。

...I don't believe it has reached the constructor yet, it's just allocating memory before jumping to the constructor. It has also executed this code dozens of times by the time it crashes, usually in a consistent (but otherwise non-suspicious) location.

问题消失与/ MTD或/ MDD(调试运行时)编译时,回来使用/ MT或者/ MD。

The problem goes away when compiling with /MTd or /MDd (debug runtime), and comes back when using /MT or /MD.

空从堆栈中加载的,我可以看到它在内存视图。 _RtlAllocateHeap @ 12 + 0x26916字节似乎是一个的巨大的偏移量,就像一个不正确的跳跃已经取得进展。

The NULL is loaded from the stack, and I can see it in memory view. _RtlAllocateHeap@12 + 0x26916 bytes seems like a huge offset, like an incorrect jump has been made.

我试过 _HAS_ITERATOR_DEBUGGING 在调试版本,而且并没有带来任何东西可疑。

I've tried _HAS_ITERATOR_DEBUGGING in a debug build and that hasn't brought up anything suspicious.

在开始和记录结束删除一个HeapValidate ::激活addField显示了一个OK的堆直到它崩溃时到。

Dropping a HeapValidate at the beginning and end of Record::addField shows an OK heap right up to when it crashes.

这用来工作 - 我不完全知道什么之间现在,我们编译工具的最后时间(可能是几年前,也许下一个旧VS)的变化。我们试过旧版本的提振(1.36 VS 1.38)。

This used to work -- I'm not entirely sure what changed between now and the last time we compiled the tool (probably years ago, maybe under an older VS). We've tried an older version of boost (1.36 vs 1.38).

下探回code人工调查或喂养这对PC - 皮棉,并通过其输出梳理之前,如何有效地调试这个有什么建议?

Before dropping back to manual investigation of the code or feeding this to PC-Lint and combing through its output, any suggestions on how to effectively debug this?

[我会很乐意与更多的信息,以更新的问题,如果您请求在评论信息]

[I'll be happy to update the question with more info, if you request info in the comments.]

推荐答案

一个小知道附加调试运行与否的区别是OS调试堆(见<一href=\"http://stackoverflow.com/questions/1060337/why-does-my-stl-$c$c-run-so-slowly-when-i-have-the-debugger-ide-attached/1060929#1060929\">Why我的code运行缓慢时,我有调试器附加?)。您可以通过使用环境变量_NO_DEBUG_HEAP关闭调试堆了。您可以在您的计算机属性指定此任,或者在项目设置在Visual Studio中。

One little know difference between running with debugger attached or not is the OS Debug Heap (see also Why does my code run slowly when I have debugger attached?). You can turn the debug heap off by using environment variable _NO_DEBUG_HEAP . You can specify this either in your computer properties, or in the Project Settings in Visual Studio.

一旦你关闭调试堆了,你应该可以看到同样的崩溃甚至与附加的调试器。

Once you turn the debug heap off, you should see the same crash even with debugger attached.

这是说,要知道内存损坏可能很难调试,经常腐败(像一些缓冲区溢出)的真正原因可能是从那里你看到的症状(崩溃)很远。

That said, be aware memory corruptions can be hard to debug, as often the real cause of the corruption (like some buffer overrun) may be very far from where you see the symptoms (the crash).

这篇关于/ MT和/ MD建立崩溃,但只有当未安装调试器:如何调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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