C++ CMake 构建模式 RelWithDebInfo

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1239845/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 19:17:05  来源:igfitidea点击:

CMake build mode RelWithDebInfo

c++visual-studiocmake

提问by sideproject

I think that I understand the difference between Release and Debug build modes. The main differences being that in Debug mode, the executable produced isn't optimized (as this could make debugging harder) and the debug symbols are included.

我想我了解 Release 和 Debug 构建模式之间的区别。主要区别在于,在 Debug 模式下,生成的可执行文件没有优化(因为这可能会使调试更加困难)并且包含调试符号。

While building PCRE, one of the external dependencies for WinMerge, I noticed a build mode that I hadn't seen before: RelWithDebInfo.

在构建 PCRE(WinMerge 的外部依赖项之一)时,我注意到了一种我以前从未见过的构建模式:RelWithDebInfo。

The difference between Debug and RelWithDebInfo is mentioned here: http://www.cmake.org/pipermail/cmake/2001-October/002479.html. exerpt: "RelwithDebInfo is quite similar to Release mode. It produces fully optimized code, but also builds the program database, and inserts debug line information to give a debugger a good chance at guessing where in the code you are at any time."

这里提到了 Debug 和 RelWithDebInfo 之间的区别:http://www.cmake.org/pipermail/cmake/2001-October/002479.html 。摘录:“RelwithDebInfo 与 Release 模式非常相似。它生成完全优化的代码,但也构建程序数据库,并插入调试行信息,使调试器有机会随时猜测您在代码中的位置。”

This sounds like a really good idea, however not necessarily obvious how to set up. This link describes how to enable this for VC++: http://www.cygnus-software.com/papers/release_debugging.html

这听起来是个好主意,但不一定很明显如何设置。此链接描述了如何为 VC++ 启用此功能:http: //www.cygnus-software.com/papers/release_debugging.html

Am I missing something, or does it not make sense to compile all release code as RelWithDebInfo?

我是否遗漏了什么,或者将所有发布代码编译为 RelWithDebInfo 没有意义?

采纳答案by Juan

Am I missing something, or does it not make sense to compile all release code as RelWithDebInfo?

我是否遗漏了什么,或者将所有发布代码编译为 RelWithDebInfo 没有意义?

It depends on how much you trust your customer with the debugging information.

这取决于您对客户的调试信息信任程度。

Additional Info:

附加信息:

gcc encodes the debugging information into the object code.

gcc 将调试信息编码到目标代码中。

Here is the pdb equivalent for gcc:

这是 gcc 的 pdb 等效项:

How to generate gcc debug symbol outside the build target?

如何在构建目标之外生成 gcc 调试符号?

Note, that cmake doesn't appear to support this approach out of the box.

请注意,cmake 似乎不支持这种开箱即用的方法。

回答by Kim Gr?sman

As far as I'm concerned, shipping code to customers without having corresponding debug symbols stored in-house is a recipe for hair-loss when it comes to debugging production problems.

就我而言,在没有内部存储相应调试符号的情况下将代码交付给客户是调试生产问题时脱发的秘诀。

Debugging Release builds with debug symbols is rarely any different from debugging Debug builds, so I'd recommend always doing this.

使用调试符号调试发布版本与调试调试版本几乎没有什么不同,因此我建议始终这样做。

That said, I don't know if there are any drawbacks. It'd be interesting to hear, if so.

也就是说,我不知道是否有任何缺点。如果是这样,听到会很有趣。

回答by sbi

Once you have tried to debug an optimized release build, you know why this is something you only want to do when there is no other way out.

一旦您尝试调试优化的发布版本,您就会知道为什么这是在没有其他出路的情况下您只想做的事情。

Basically, I see two cases when you'll need this:

基本上,我看到两种情况,当您需要它时:

  • You have a problem that doesn't appear in debug builds, so you have to debug a release build
  • You have a crash at a customers and use the locally stored debug info to understand the crash.
  • 你有一个没有出现在调试版本中的问题,所以你必须调试一个发布版本
  • 您在客户处发生崩溃并使用本地存储的调试信息来了解崩溃。

I don't know about you, but I had to debug release code twice or thrice in the last decade and managed to work at companies where crashes at customer's were no issue.

我不了解你,但在过去的十年里,我不得不调试发布代码两次或三次,并设法在客户崩溃不成问题的公司工作。

Yeah, it's probably a good idea to have debug info for your release builds, too, but VS doesn't set things up this way and for the two cases in each decade where you need this it isn't worth setting this up manually every time. Since CMake gives it for free, do it.

是的,为您的发布版本提供调试信息可能也是一个好主意,但是 VS 不会以这种方式进行设置,对于每十年中需要此信息的两种情况,不值得每次手动设置时间。既然 CMake 是免费提供的,那就去做吧。

回答by thekidder

Production code doesn't need the size bloat that debugging information carries.

生产代码不需要调试信息携带的大小膨胀。

回答by D?enan

Even when debug info is produced for release build, it is far less useful for debugging purposes than debug build. The reason is that many variables and intermediate expressions are optimized away, and are hence unavailable in the debugger.

即使为发布版本生成调试信息,它对于调试目的的用处也远不如调试版本。原因是许多变量和中间表达式被优化掉了,因此在调试器中不可用。