CMake build mode RelWithDebInfo

2019-03-24 18:55发布

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.

While building PCRE, one of the external dependencies for WinMerge, I noticed a build mode that I hadn't seen before: 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."

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

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

5条回答
我命由我不由天
2楼-- · 2019-03-24 19:05

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.

查看更多
来,给爷笑一个
3楼-- · 2019-03-24 19:06

Am I missing something, or does it not make sense to compile all release code as 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.

Here is the pdb equivalent for gcc:

How to generate gcc debug symbol outside the build target?

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

查看更多
forever°为你锁心
4楼-- · 2019-03-24 19:06

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

查看更多
Rolldiameter
5楼-- · 2019-03-24 19:18

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.

查看更多
走好不送
6楼-- · 2019-03-24 19:30

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.

查看更多
登录 后发表回答