简体   繁体   English

如果调试运行正常但释放崩溃怎么办

[英]what to do if debug runs fine, but release crashes

I have an application that runs just fine in the debug build, but when I start it in the release build, I get a 我有一个可以在调试版本中正常运行的应用程序,但是当我在发行版本中启动它时,会得到一个

unhandled Exception at 0x0043b134 in myapp.exe: 0xC0000005:
Access violation while reading at position 0x004bd96c

If I click on 'break' it tells me that there are no symbols loaded and the source code can't be displayed. 如果单击“中断”,则表明没有加载符号,并且无法显示源代码。

What can I do in such a situation to track down the problem? 在这种情况下我该怎么办才能找出问题所在?

This kind of problem is often due to unitialized variables. 这种问题通常是由于单位变量引起的。 I'd start there looking for your problem. 我将从那里开始寻找您的问题。

Debug mode is more forgiving because it is often configured to initialize variables that have not been explicitly initialized. 调试模式更为宽容,因为它通常配置为初始化尚未显式初始化的变量。

Perhaps you're deleting an unitialized pointer. 也许您要删除一个统一的指针。 In debug mode it works because pointer was nulled and delete ptr will be ok on NULL. 在调试模式下,它起作用是因为指针已为空,并且删除ptr可以为NULL。 On release it's some rubbish, then delete ptr will actually cause a problem. 发布时有些垃圾,然后删除ptr实际上会引起问题。

It could be two things: 可能有两件事:

  • One or more of your assertions does necessary work apart from the check itself 除了检查本身之外,您的一个或多个断言还可以进行必要的工作
  • Something else 还有别的

To rule out the former, try redefining assert as an empty operation in the debug build. 要排除前者,请尝试在调试版本中将assert重新定义为空操作。 If the absence of some assertion causes the crash, you will see it. 如果缺少某些断言导致崩溃,您将看到它。 Otherwise, it's something else. 否则,这是另一回事。

Also, I assume you have version control. 另外,我假设您具有版本控制权。 Did this just start happening? 这刚刚开始发生吗? You can analyze the code changes from last week. 您可以分析上周以来的代码更改。

Finally, even in the absence of a crash in debug mode, running a memory checker tool may be useful to spot incorrect memory access. 最后,即使在调试模式下没有崩溃,运行内存检查器工具也可能有助于发现错误的内存访问。

Two steps: 两步:

a) Build release build with debug symbols (possible with VS at least) a)带有调试符号的版本发行版(至少在VS中可用)

b) Build release build without optimization b)无需优化即可构建发行版本

If the problem still happens, it is very good and easy to fix. 如果问题仍然存在,则非常好且易于修复。 It is almsot as if the problem is in debug build. 好像问题出在调试版本中一样。

If the problem happens with optimization settings on, then it is really tough and has to be handled in situation specific manner. 如果在启用优化设置的情况下发生问题,那么这确实很困难,必须根据具体情况进行处理。

I had this problem, release/debug worked fine inside visual studio, debug work stand alone, but release crashed stand alone. 我遇到了这个问题,发布/调试在Visual Studio中运行良好,单独调试工作,但是发布崩溃了。 Debugging was not particularly accurate for me, my solution was: 调试对我而言不是特别准确,我的解决方案是:

Comment out most of the code, then build, test, uncomment, repeat, until you find the section that causes the crash. 注释掉大多数代码,然后构建,测试,取消注释,重复,直到找到导致崩溃的部分。

In my case it was passing a pointer to an array that was too small to a function. 在我的情况下,它传递的指针指向的数组对于函数而言太小。

Are you sure that both releases use the same .dll ? 您确定两个版本都使用相同的.dll吗? I spend an hour wondering why my program did compile in debug mode but not in release mode and I just forgot to update the dll's in the release folder. 我花了一个小时想知道为什么我的程序没有在调试模式下进行编译,而在发布模式下进行了编译,却忘记了更新发布文件夹中的dll。

main功能的开头一直跟踪到此插入日志输出的问题。

If it is not a memory issue, then you have to enable asserts in the release. 如果不是内存问题,则必须在发行版中启用断言。 For memory issues, I hope you got good unit tests. 对于内存问题,希望您获得了不错的单元测试。 You can easily catch such problems with valgrind. 您可以使用valgrind轻松捕获此类问题。

btw why are people disabling asserts in the release version? 顺便说一句,为什么人们禁用发行版中的断言? In 99% cases they do not cause performance problems, and are good in detecting errors. 在99%的情况下,它们不会导致性能问题,并且可以很好地检测错误。

For me, the problem was that a constructor was initializing 2 member variables in the wrong order. 对我来说,问题在于构造函数以错误的顺序初始化2个成员变量。 ie not the same order that they were declared in. 也就是说,它们的声明顺序不同。
I'm surprised that initialization order actually makes any difference. 我很惊讶初始化顺序实际上没有任何作用。

Take a crash dump using Microsoft debugdiag on windows(it's free) and analyze the dump using the same. 在Windows上使用Microsoft debugdiag (免费)进行故障转储,并使用相同的程序分析转储。 It gives a nice call stack for the function where it crashes. 它为崩溃的函数提供了一个不错的调用堆栈。 Although, if it keeps crashing all over the place, it could be an issue of heap corruption. 虽然,如果它仍然到处崩溃,那可能是堆损坏的问题。 You then need to use global flags(or gflags which is a part of microsoft tools for debugging suite which is free) in conjunction with debugdiag. 然后,您需要与debugdiag结合使用全局标志(或gflags,这是Microsoft用于调试套件的工具的一部分,它是免费的)。 Gflags would give you the location where the heap is actually getting corrupted. Gflags将为您提供堆实际上已损坏的位置。 Hope that helps. 希望能有所帮助。

Without looking at the code, it is hard to tell what is bad. 如果不看代码,很难说出什么不好。 All the above suggestions are good and helpful but what I have found most helpful fixing this kind of things is to run certain parts of program in chunks. 以上所有建议都是有益且有用的,但是我发现最有效的解决此类问题的方法是分批运行程序的某些部分。 ie, comment out a lot of code/functionality and then run the program and see if it crashes. 即,注释掉很多代码/功能,然后运行程序,看看它是否崩溃。 If it doesn't, the uncomment some functionality and then re-run again and so on. 如果不是,则取消注释某些功能,然后重新运行,依此类推。 This way you will be able to narrow down the problem to the exact code that is causing this. 这样,您就可以将问题缩小到导致此问题的确切代码。

In most of the cases this happens due to some Buffer overruns which Debug builds can guard against. 在大多数情况下,这种情况的发生是由于Debug构建可以防止的某些Buffer超载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM