This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Difference b/w release & debug

I read that there are two diff:

1. Debug settings have debug information with it, while release don't have it.
2. Debug has lower optimization settings compared to release for better debug view.

My queries:
1. What kind of debug information in point 1.
2. If I set same debug optimization settings as of release then will the code be same.
3. Keil don't have separte debug & release settings. In "project target" we can select same project with different opt settings but it don't have separate settings for release. So where is debug info in this case
4. On all Eclipse based & IAR compiler also have separate release & debug settings. In IAR option I check that in option there is macro defined "NDEBUG" if I select release settings. I didn't it anywhere else in project. So what benefit it gives except like certain features can be added like:

ifndef(NDEBUG)
// blonk led to indicate debug is attached

5. What if in my final code, I keep debug setting & change opt level that I need. Will my application will be slower.
  • Aamir Ali said:
    I read that there are two diff:

    IIRC that's the default.

    Basically, you can rename 'debug' and 'release' by 'option set 1' and 'option set 2'. Both are independent project option sets that default to something that is likely useful for the expressed purpose.

    Typical differences are:
    In 'debug' you'll have a token (not a macro, a macro is a token with parameters) defined that allows your program to conditionally compile debug code.
    Also, both option sets usually define different compiler parameters (like the optimization level) and linker options (like the amount of debug code to embed into the output file).

    You should be able to figure out which commandline parameters are passed to compiler and linker and what they mean. Or this info is already in the compiler and linker users guides.

    By flipping the settings, you can exchange the meaning of 'debug ' and 'release'.

    To answer your questions:

    1. depends on what commandline parameter is passed to the linker. In general, debug info contains names and addresses of functions, names and addresses of variables or even reference tables for binding a certain binary address to a certain source code line. In release mode, the last one is usually disabled, so you can't step through your source code, as the debugger won't know which source line belongs to the current point of execution.

    2. normally, yes. Unless in debug mode there are additional compiler parameters used that affect code generation. Also see 4.

    3. maybe the Keil compiler always includes the debug info. Or choosing a higher optimization level disables the debug info output automatically (as it won't help you debugging the optimized code anyway).

    4. exactly that's the reason: to include or exclude debug code based on the selected build mode. One should keep in mind that even with same optimization level for debug and release, code will be different if this feature is used for conditional compilation. And removing the debug code may affect or even break the application that did run perfectly in debug mode.
    Example: in Linux/Java we had some code that stopped working when the line with the debug output was excluded in release mode. Of course without debug output, debugging was difficult. It turned out that writing the debug output caused a (unintended and unnoticed) thread switch that was not occurring when the debug output was disabled. And due to the then missing thread switch, a racing condition became critical that was no problem before.

    5. Depends on your changes. If you use same optimization level and do not conditionally compile debug code, and do not use the debugger, your application binary (not the output file, but the code part that is written into the MSP) should be identical and both versions will (of course) run at same speed.
    If you don't use same optimization level, well, speed and size change of course depend on the optimization level you choose. And the 'quality' of your source code, regarding the possibility to do any optimization at all.

**Attention** This is a public forum