Common reasons for bugs in release version not present in debug mode

后端 未结 18 1450
余生分开走
余生分开走 2020-11-28 04:11

What are the typical reasons for bugs and abnormal program behavior that manifest themselves only in release compilation mode but which do not occur when in debug mode?

相关标签:
18条回答
  • 2020-11-28 04:34

    It's possible. If it happens and no conditional compilation is involved, than you can be pretty sure that your program is wrong, and is working in debug mode only because of fortuitous memory initializations or even layout in memory!

    0 讨论(0)
  • 2020-11-28 04:37

    Other differences might be:

    • In a garbage-collected language, the collector is usually more aggressive in release mode;
    • Layout of memory may often be different;
    • Memory may be initialized differently (eg could be zeroed in debug mode, or re-used more aggressively in release);
    • Locals may be promoted to register values in release, which can cause issues with floating point values.
    0 讨论(0)
  • 2020-11-28 04:37

    The CRT library functions behave differently in debug vs release (/MD vs /MDd).

    For example, the debug versions often prefill buffers you pass to the indicated length to verify your claim. Examples include strcpy_s, StringCchCopy, etc. Even if the strings terminate earlier, your szDest better be n bytes long!

    0 讨论(0)
  • 2020-11-28 04:38

    There are compiler optimizations that can break valid code because they are too aggressive.

    Try compiling your code with less optimization turned on.

    0 讨论(0)
  • 2020-11-28 04:38

    I remember while ago when we were building dll and pdb in c/c++.

    I remember this:

    • Adding log data would sometime make the bug move or disappear or make a totally other error appears (so it was not really an option).
    • Many of these errors where related to char allocation in strcpy and strcat and arrays of char[] etc...
    • We weeded some out by running bounds checker and simply fixing the memory alloc/dealloc issues.
    • Many times, we systematically went through the code and fixed a char allocation.
    • My two cents is that it is related to memory allocation and management and constraints and differences between Debug mode and release mode.

    And then kept at going through that cycle.

    We sometimes, temporarily swapped release for debug versions of dlls, in order not to hold off production, while working on these bugs.

    0 讨论(0)
  • 2020-11-28 04:39

    Another reasons could be DB calls. Are you saving and updating same record multiple times in same thread, sometimes for updating. Its possible the update failed or didnt work as expected because the previous create command was still processing and for update, the db call failed to find any record. this wont happen in debug as debugger makes sure to complete all pending tasks before landing.

    0 讨论(0)
提交回复
热议问题