Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug in release mode?

I have to debug a c++ project, but as one dependency doesn't compile in debug mode and I haven't been able to fix that issue so far, I'd like to try to debug the project in release mode.

Currently the application crashes due to a null pointer, but I haven't the code that's causing the error. As break points apparently are ignored in release-mode, I'd like to know what's the best way find the error.

like image 753
Pedro Avatar asked Jun 28 '12 21:06

Pedro


People also ask

Can I debug in release mode Android studio?

It means you have to give sign build in debug version also in build gradle. So It will have the same sign as release build and you can debug when it runs.

What is debug mode and release mode?

In Debug Mode your .exe has debug information inside of it (source code, variable names and other similar stuff like that). In Release Mode your .exe lack of debug information makes it smaller and probably performs better due to its smaller footprint.

How do you debug in release mode flutter?

To display information that you would like to be visible in release mode ('production code') of your flutter app, simply use print() method. For info you want to hide in console log use debugPrint() .

Can you use breakpoints in release mode?

You can then put a breakpoint on that int declaration line, and it'll be hit, even in release mode. Then just step up the stack in the debugger back to the function you actually wanted a breakpoint in.


2 Answers

In VS, right click your project, chose "Properties".

  1. Click the C/C++ node. Set Debug Information Format to C7 compatible (/Z7) or Program Database (/Zi).

  2. Expand Linker and click the General node. Set Enable Incremental Linking to No (/INCREMENTAL:NO).

  3. Select the Debugging node. Set Generate Debug Info to Yes (/DEBUG).

  4. Select the Optimization node. Set References to Yes (/OPT:REF).

    if /OPT:REF is specified, /OPT:ICF is on by default.

That's ripped directly from Microsoft's documentation:

  • How to: Debug a Release Build
  • OPT Optimizations

I do this all of the time and pretty much never debug in debug mode anymore. As you know, many errors that occur in a release build may not occur in a debug build (almost certainly the errors that arise from invoking UB).

Also, I work on a project which uses a ton of image processing and performs a lot of compression/decompression of large images. Using a slow debug build is simply impractical.

like image 80
Ed S. Avatar answered Sep 20 '22 01:09

Ed S.


You can't always just change the project settings and recompile.
Sometimes you have a released version which you would like to debug, or a dump file sent by a client.

When compiling a C++ project in release with optimizations, the debugger sometimes doesn't show the right object information.

The local variables are usually the first to go, and many times, the this object's information is lost to the debugger.

The reason is that the compiler uses the available hardware registers to hold the information, and uses optimizations to avoid allocation of local variables.

I've suggested a way to find the missing information here:

Debugging Release Projects in C++ - Finding the Lost Object Information

like image 34
Yochai Timmer Avatar answered Sep 23 '22 01:09

Yochai Timmer