简体   繁体   English

没有调试符号的程序崩溃,运行正常(在任何情况下都没有优化或任何东西)

[英]Program crashes without debug symbols, runs fine with them (no optimizations or anything in either case)

I've come across a very baffling crash and having trouble tracing it in my program. 我遇到了一个非常令人困惑的崩溃,并且无法在我的程序中跟踪它。

I have no idea where its source is, because whenever I attempt to link with the /debug flag in order to debug with debug symbols, the crash disappears! 我不知道它的来源在哪里,因为每当我尝试与/debug标志链接以便使用调试符号进行调试时,崩溃就会消失!

This seems to be independent of optimizations (I've compiled with /Od to disable compiler optimizations and I'm not using link-time code generation) and also independent of debug information itself (I'm compiling with /Zi ). 这似乎与优化无关(我用/Od编译来禁用编译器优化而我没有使用链接时代码生成)并且也独立于调试信息本身(我用/Zi编译)。 For some reason, when the linker is called without the /debug flag, everything behaves differently. 出于某种原因,在没有/debug标志的情况下调用链接器时,一切都表现不同。

What could possibly be causing this? 什么可能导致这个?

It turned out the culpirit was merging of static const int fields by the linker. 事实证明,culpirit正在通过链接器合并static const int字段

Apparently, if you have multiple static const fields of the same type and value, the linker will merge them, but only if you don't link debug symbols. 显然,如果您有多个相同类型和值的static const字段,链接器将合并它们,但前提是您不链接调试符号。

I was using the addresses of such fields to distinguish between them, and as it turned out they all looked the same to the linker, and hence to the rest of the code. 我使用这些字段的地址来区分它们,结果看起来它们对链接器看起来都是一样的,因此对代码的其余部分也是如此。

How did I figure this out? 我怎么知道这个?
Lots and lots of print statements (hours) led me to realize that the wrong code is being executed, until I finally realized the cause. 大量print语句(小时)让我意识到错误的代码正在执行,直到我终于意识到原因。

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

相关问题 SFML 2.1程序在调试模式下运行良好,但在发布模式下崩溃 - SFML 2.1 program runs fine in debug mode, but crashes in release mode 如果调试运行正常但释放崩溃怎么办 - what to do if debug runs fine, but release crashes 如何在没有调试符号且没有优化的情况下创建cmake构建配置? - How to create cmake build configuration without debug symbols and without optimizations? 带有断点的代码运行良好,但没有断点就不行 - Code runs fine with breakpoints but NOT without them 问答程序在发布版本时崩溃,在调试版本中运行良好 - Question and Answer program crashes on release build, works fine on debug build VS2010 Express建议在调试模式下进行优化,并且在没有优化的情况下无法运行应用程序 - VS2010 Express recommends optimizations in debug mode, and fails running the app without them 调试时我的代码运行正常,但是一旦运行它就会崩溃 - My code runs fine when I debug it, but crashes as soon as I run it 调试运行良好,但不在发布模式下 - Debug runs fine, but not in release mode 程序使用“windows 本地调试器”运行,但在以发布或调试模式构建后运行 .exe 文件时不运行 - Program runs with 'windows local debugger' but not when running the .exe file after building in either release or debug mode 调试失败,程序崩溃 - Debug fails, program crashes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM